Results 1 to 2 of 2
  1. #1
    omerkhalid34 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Post Problem using HashTable and HashMap duplicate insertions

    i think hashtable can allow multiple values with same key. But how can i look at all the values with the same key. I have just far reached uptill here
    in both the cases of the while loop it shows only the values 1, 2 , and 4. If it allows multiple values with the same key then it must show 3 and 4 for the same key which is 3. But it is not showing here. or i don't know how to print the values.
    Hashtable<String,String> m = new Hashtable<String,String>();

    m.put("1","1");
    m.put("2","2");
    m.put("3","3");
    m.put("3","4");

    Set set = m.keySet(); // get set-view of keys
    Set set1 = m.entrySet(); //get set of all values in hash table

    // get iterator
    Iterator itr = set.iterator();
    Iterator itr1 = set1.iterator();

    String str;
    double bal;

    while(itr.hasNext())
    {

    str = (String) itr.next();
    System.out.println(str + ": " +m.get(str));
    }
    while(itr1.hasNext())
    {

    Map.Entry e = (Map.Entry) itr1.next();
    System.out.println(e.getValue());
    }

    but in both cases the output is
    1 : 1
    2 : 2
    3 : 4

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Problem using HashTable and HashMap duplicate insertions

    Duplicate post -- locked.

    Original poster, duplicate posting is not fair to the volunteers of this forum as it needlessly divides discussions. Please read the FAQ's and abide by the forum rules regarding this and our other rules.

Similar Threads

  1. HashTable and Hash Map are not Showing duplicate values
    By omerkhalid34 in forum New To Java
    Replies: 1
    Last Post: 01-14-2012, 02:43 PM
  2. How does HashMap differ from HashTable?
    By guest_user in forum New To Java
    Replies: 1
    Last Post: 08-12-2011, 04:05 PM
  3. HashTable vs HashMap
    By bugger in forum New To Java
    Replies: 7
    Last Post: 01-06-2011, 03:15 PM
  4. Problem with Hashtable key.
    By XmisterIS in forum New To Java
    Replies: 7
    Last Post: 09-11-2010, 08:19 AM
  5. How to make a hashmap to allow duplicate values?
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 12:35 PM

Tags for this Thread

Posting Permissions

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