Results 1 to 3 of 3
- 12-12-2008, 11:59 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 53
- Rep Power
- 0
Convert Linked List Object element to String
Hello,
I have a linked list with the following elements (A,B,C,D)
I created a method to copy the first Node and store it an Object variable called tempNode.
After running the method the tempNode is now set as "A"
So how do I convert this "A" object into a string?
Ive tried this
String newTempNode = new String(tempNode);
and it is complaining about the following
cannot find symbol
symbol: constructor String (java.lang.Object)
location: class java.lang.String
I figured I needed to import a class so I did this
import java.lang.Object;
import java.lang.String;
still gets the same error. What am I doing wrong?
-
What do you mean "convert an object into a String"? There is no generic way to get a String representation of an object other than by calling its toString method. i.e.:
but if the tempNode object's class doesn't have a toString override, the only thing that will come out will be gibberish.Java Code:String myString = tempNode.toString();
- 12-13-2008, 05:22 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM -
Linked List help
By neobie in forum New To JavaReplies: 8Last Post: 12-22-2007, 03:15 AM -
going from vectors to linked list?
By cbrown08 in forum New To JavaReplies: 3Last Post: 12-01-2007, 12:55 AM -
Linked List
By rnavarro9 in forum New To JavaReplies: 0Last Post: 11-29-2007, 03:42 AM -
Help with linked list
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks