Results 1 to 5 of 5
- 03-31-2011, 08:28 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 41
- Rep Power
- 0
getting first item in a linkedList
I have the method below that is supposed to return the first item in a doubly linked list:
I then call the method like this:Java Code:private Node<T> head; public Node<T> returnHead() { return head; }
I don't get any errors, but I get this strange string returned:Java Code:System.out.println("Head = " + myLinkedList.returnHead());
Head = myLinkedList$Node@42e816
I'm not sure exactly what this is I'm getting. The items in the list are a list of books(String).
Any help would be greatly appreciated.
Thanks!
- 03-31-2011, 08:32 PM #2
It's because the Node<T> object has no good toString() method, so it returns what appears to be gibberish. (It's really not, but I'm not sure you really want to know what it means...)
So, you can either give all your nodes in there a toString() method that displays something usable, or pick specific member variables from it to display instead.
- 04-01-2011, 02:22 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 41
- Rep Power
- 0
Thanks...for a toString method I just need to convert it to string? .NET has a toString function built-in...how does one do that in Java?
Thanks again
- 04-01-2011, 02:49 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Every object in java has toString method (is used by println statements to print the object), which by default does what the API says it does (see Object (Java Platform SE 6) ). Override this function if you wish this method to returns something different
- 04-01-2011, 03:26 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
I need help in LinkedList ...
By Usman in forum Advanced JavaReplies: 3Last Post: 03-25-2011, 01:38 AM -
NullPointer adding an item to a LinkedList
By sehudson in forum New To JavaReplies: 7Last Post: 03-10-2011, 03:39 AM -
LinkedList
By [RaIdEn] in forum New To JavaReplies: 7Last Post: 10-13-2009, 12:59 AM -
LinkedList help
By jigglywiggly in forum New To JavaReplies: 6Last Post: 09-19-2009, 07:24 AM -
how to use LinkedList
By fred in forum Advanced JavaReplies: 1Last Post: 07-24-2007, 01:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks