Results 1 to 3 of 3
  1. #1
    CirKuT is offline Member
    Join Date
    Sep 2008
    Posts
    53
    Rep Power
    0

    Default 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?

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

    Default

    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.:
    Java Code:
    String myString = tempNode.toString();
    but if the tempNode object's class doesn't have a toString override, the only thing that will come out will be gibberish.

  3. #3
    carlodelmundo is offline Member
    Join Date
    Aug 2008
    Posts
    31
    Rep Power
    0

    Default

    Cirkut, can you post your linked list class code? Like Fubarable said, once you create a toString() method in your linked list class you can get the string representation of the object.

Similar Threads

  1. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM
  2. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 04:15 AM
  3. going from vectors to linked list?
    By cbrown08 in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 01:55 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 04:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •