TreeMap Map.Entry firstEntry() Method Example Program


Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

Program

package com.candidjava;

import java.util.TreeMap;

/**
 * @author: Hari Haran
 * @discription:The firstEntry() method is used to return a key-value mapping
 *                  associated with the least key in this map, or null if the
 *                  map is empty.
 */

public class TreeMapFirstEntry {
	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 first entry");
		System.out.println("First entry is: " + tm.firstEntry());
	}
}

Output

Checking first entry
First entry is: 1=Anand

Explanation

public Map.Entry<K,V> firstEntry()
Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
Specified by:
firstEntry in interface NavigableMap<K,V>
Returns:
an entry with the least key, or null if this map is empty


Related Post

Comments


©candidjava.com