10:58 am - Sunday April 30, 2017

To Check First and Last Key in TreeMap using lastkey() & firstkey()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This tutorial explains how  to find first and last key in treemap using firstkey() & lastkey() method.The same

   way first value also checked among the list.If the value is found means just return the value.

Example

import java.util.Comparator;
import java.util.Map.Entry;

import java.util.TreeMap;

public class TreeMapChecking

{

public static void main(String[] args)

{

   TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

   treemap.put(2, "two");

   treemap.put(1, "one");

   treemap.put(3, "three");

   treemap.put(6, "six");

   treemap.put(5, "five");

   System.out.println("last key   :  "+ treemap.lastKey());

   System.out.println("First Key  :  "+treemap.firstKey());

 }
}

Output 

          last key     :  6

          First Key  :  1

 

 

BACK

Filed in: Java Examples

Comments are closed.