Results 1 to 4 of 4
- 09-25-2011, 04:59 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
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....
- 09-25-2011, 05:23 PM #2
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:
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.display the entries i get the output as some string --> LinkedList@3443
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?Last edited by Norm; 09-25-2011 at 05:28 PM. Reason: There is toString that formats
- 09-25-2011, 05:49 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
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 hashtableLast edited by Joker2012; 09-25-2011 at 06:03 PM.
- 09-25-2011, 06:00 PM #4
Similar Threads
-
hashtable
By kmm1977 in forum New To JavaReplies: 4Last Post: 01-20-2011, 04:24 PM -
hashtable
By vijayabaskar in forum Java ServletReplies: 0Last Post: 04-06-2009, 08:20 AM -
hashtable
By vijayabaskar in forum Advanced JavaReplies: 2Last Post: 04-06-2009, 08:05 AM -
Hashtable
By angelicsign in forum New To JavaReplies: 6Last Post: 02-05-2009, 04:30 PM -
Hashtable example
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 08:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks