Results 1 to 6 of 6
  1. #1
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Question hashTable restructuring

    i have a hashTable<Integer, noteHeader>

    the noteHeader class is:

    Java Code:
    public class noteHeader {
        public String displayText;  
        public String noteText;  
        
        public noteHeader(String text1, String text2){
            this.displayText = text1;
            this.noteText = text2;
        }
    }
    the keys are sequential numbers.
    my question is, when i remove an item, how can i modify all of the keys after the removed item so the hashTable keys are still sequential numbers?

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

  3. #3
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: hashTable restructuring

    it's the only way. i need to remove an element from the hashTable when a jList item is removed. the keys correspond to the jList list indices + not modifying the hashTable is not an option.

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

    Default Re: hashTable restructuring

    Quote Originally Posted by .paul. View Post
    it's the only way. i need to remove an element from the hashTable when a jList item is removed. the keys correspond to the jList list indices + not modifying the hashTable is not an option.
    It's always an option, and you've yet to convince me otherwise yet (I'm stubborn). Why are you using a HashTable to begin with since this has been largely superseded by HashMap? Why not simply an ArrayList if you need the indices to re-align so that it remains monotonically increasing and without gaps?

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: hashTable restructuring

    Why are you using a HashTable / Map at all? Why not a List?

  6. #6
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: hashTable restructuring

    Quote Originally Posted by Fubarable View Post
    Why are you using a HashTable to begin with since this has been largely superseded by HashMap?
    i'm new to java + the internet can be a misleading place.

    Quote Originally Posted by Fubarable View Post
    Why not simply an ArrayList if you need the indices to re-align so that it remains monotonically increasing and without gaps?
    thankyou.

Similar Threads

  1. Hashtable question. Getting info from a hashtable
    By sindrem in forum New To Java
    Replies: 4
    Last Post: 01-19-2012, 05:00 PM
  2. hashtable
    By vijayabaskar in forum Java Servlet
    Replies: 0
    Last Post: 04-06-2009, 08:20 AM
  3. hashtable
    By vijayabaskar in forum Advanced Java
    Replies: 2
    Last Post: 04-06-2009, 08:05 AM
  4. Hashtable
    By angelicsign in forum New To Java
    Replies: 6
    Last Post: 02-05-2009, 04:30 PM
  5. Hashtable example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:43 AM

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
  •