Simple Example of TreeMap class in Java .

Simple Example of TreeMap class in Java .

import java.util.*;

class Test8{

public static void main(String args[]){

TreeMap hm=new TreeMap();

hm.put(2,"Amit");

hm.put(1,"Amar");

hm.put(3,"Rahul");

hm.put(2,"Alok");

Set set=hm.entrySet();

Iterator itr=set.iterator();

while(itr.hasNext()){

Map.Entry m=(Map.Entry)itr.next();

System.out.println(m.getKey()+" "+m.getValue());

}}}

output: 1 Amar
            2 Alok
            3 Rahul

Read More →