View Single Post
  #2 (permalink)  
Old 07-20-2007, 08:23 AM
tirupati.j2ee tirupati.j2ee is offline
Member
 
Join Date: Jul 2007
Posts: 1
tirupati.j2ee is on a distinguished road
Hi
Hi

actually the basic implemantion of Hash map is there is no guarantiy to the order as per the the values you put . HashMap using hashtable functionality in thats way this is using index order and another thing is if you want get values from hash table ther are two vays one thing is to get the values set from hash map using value() method it terurn Collection object than after type costing each elemetn another one is using below code

HashMap<String, Integer> hmp= new HashMap<String, Integer>();
hmp.put("1", new Integer(1));
hmp.put("5", new Integer(5));
hmp.put("3", new Integer(3));
hmp.put("4", new Integer(4));
hmp.put("2", new Integer(2));
hmp.put("6", new Integer(6));

Set st = hmp.keySet();

//SortedSet st =keySet;
Iterator it = st.iterator();
while(it.hasNext())
{
System.out.println(hmp.get(it.next()));
}

System.out.println(hmp);
Reply With Quote