LinkedList as value in a hashTable Map
i have to read from a File and store it in a HashTable with the key as String and Value as Linked list.
my example
HashTable<String,LinkedList<String>>r = new HashTable<String,LinkedList<String>>();
when i use the code
r.put("some String", ??);
what do i place at "??"
and what code do i use to display the output
when i use the code
LinkedList<String> list = new LinkedList<String>();
list.addLast("String");
then
r.put("some String", list);
and try to display the entries i get the output as
some string --> LinkedList@3443
can you please suggest me any method or code to help me place a linkedlist into a hashtable value....
Re: LinkedList as value in a hashTable Map
I think your code is placing the linkedlist in the hashtable. The following shows that it is working:
Quote:
display the entries i get the output as some string --> LinkedList@3443
The LinkeList class does not have a toString method that creates a display for its contents so it uses the Object class's default toString method which give the classname followed by @ followed by the hashcode.
To get a prettier display, you will need to write it.
EDIT:
The above appears to be wrong!
I just ran your code and got:
System.out.println(r); // {some String=[String]}
How are you displaying the contents of the Hashtable?
Re: LinkedList as value in a hashTable Map
im using a for loop
for (Entry<String, LinkedList<String>> ee: r.entries())
System.out.println(ee.getKey() + " ==> " + ee.getValue());
sorry im using m3 as my hashtable
Re: LinkedList as value in a hashTable Map
What is m3?
What package is the class Entry in?