Results 1 to 3 of 3
  1. #1
    dredd is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default How can I remove items from Hashtable<String, Integer> by int as indices?

    How can I remove items from Hashtable<String, Integer> by int as indices?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: How can I remove items from Hashtable<String, Integer> by int as indices?

    You can't, at least not directly. A Hashtable is not a linear list of elements but a list of other lists of elements. So when you specify a key, it hashes to the correct "bucket" where your value is stored. This bucket is then searched for the key you supplied to return the value. Therefore, there is no set order of a Hashtable. The methods and therefore storage order for both lists should be of no concern to the user as the Hashing algorithms and such could change in future releases.

    What you could do is have an ArrayList of keys. So when you want to remove say "item #N" in the Hashtable, get the key for item #N in the ArrayList. Then use that key to remove the Hashtable item. You would then probably remove the key out of the ArrayList too since it no longer maps to anything.

    Regards,
    Jim
    Last edited by jim829; 04-16-2013 at 01:48 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: How can I remove items from Hashtable<String, Integer> by int as indices?

    What is it you are doing that you think you need to remove something by an index?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How do I create a String[2][20], with only 10 items
    By LCounter in forum New To Java
    Replies: 1
    Last Post: 04-21-2011, 12:16 AM
  2. jList - add/remove items and query - using jFrame Form
    By ArneBassez in forum AWT / Swing
    Replies: 2
    Last Post: 12-01-2010, 12:42 PM
  3. How to remove Eclipse context menu items?
    By Neil_ in forum Eclipse
    Replies: 0
    Last Post: 04-06-2009, 05:09 AM
  4. Replies: 0
    Last Post: 07-11-2008, 04:29 PM

Posting Permissions

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