TreeMap K lastKey() Method Example Program


Returns the last (highest) key currently in this map.

Program

package com.candidjava;

import java.util.TreeMap;

/**
 * @author: Hari Haran
 * @discription:The lastKey() method is used to return the last (highest) key
 *                  currently in this map.
 */

public class TreeMapLastKey {
	public static void main(String[] args) {
		TreeMap<Integer, String> tm = new TreeMap<Integer, String>();

		tm.put(1, "Anand");
		tm.put(2, "Hari Haran");
		tm.put(8, "Kamal");
		tm.put(4, "Karthikeyan");
		tm.put(5, "Mohan");
		tm.put(6, "Vinoth");
		tm.put(7, "Hari Haran");

		System.out.println("Checking last key");
		System.out.println("Value is: " + tm.lastKey());
	}
}

Explanation

Checking last key
Value is: 8



Related Post

Comments


©candidjava.com