Results 1 to 3 of 3
  1. #1
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default how to return values from hashmap

    I want to retrieve all the values I put into a HashMap.
    But I want them to retrieve them in the order I put them in.

    Can you help me?

  2. #2
    tirupati.j2ee is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Arrow 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);

  3. #3
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 04-15-2008, 02:04 PM
  2. HashMap: Obtaining all values in a collision?
    By markus-sukram in forum New To Java
    Replies: 2
    Last Post: 03-29-2008, 11:25 PM
  3. HashMap String Return
    By kizilbas1 in forum New To Java
    Replies: 1
    Last Post: 03-10-2008, 04:34 AM
  4. How to make a hashmap to allow duplicate values?
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:35 PM
  5. Hashmap
    By dirtycash in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 03:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •