Results 1 to 5 of 5
- 01-24-2009, 08:44 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 7
- Rep Power
- 0
Convert Comparable object to string or char
Hi All,
I have a Link List of comparables that I would like to convert into one string:
I am doing something like:
Java Code:char[] LinkedListArray = null; int i = 0; while (not_end_of_linked_list) { LinkedListArray[i] = item; i++; next_in_LinkedList(); }
Cheers,
ScKaSx
- 01-25-2009, 04:43 AM #2
Please tell us what you are trying to accomplish. Your code takes each object and reduces it to a single char, which you place in an array. Not to mention you never actually created the array.
Are you wanting the save the state, or all the properties, of each object?
- 01-25-2009, 06:24 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 11
I have no idea what you're trying to accomplish with this, but you can certainly add a toString method to your Comparable implementation.
- 01-25-2009, 10:29 AM #4
Member
- Join Date
- Jan 2009
- Posts
- 7
- Rep Power
- 0
Basically I have a linked list of comparable objects that I want to concatenate together in a string. For instance, the linked list might look like:
comparable: Adam
|
v
comparable: Mike
|
v
comparble: Tom
I am looping through the linked list and for each comparable item I want to concatenate the comparable into a string so that *.toString() will give:
Adam
Mike
Tom
Any ideas on the correct implementation?
My original code has changed to one using concatenation of a String class:
Java Code:String LLstring = ""; Comparable item; while (not_end_of_linked_list) { LLstring = LLstring + item; next_in_LinkedList(); }
Cheers,
ScKaSxLast edited by ScKaSx; 01-25-2009 at 10:34 AM.
-
Similar Threads
-
Convert Linked List Object element to String
By CirKuT in forum New To JavaReplies: 2Last Post: 12-13-2008, 06:22 AM -
Anyone know how to take info from a txt file and convert it to a char array?
By 2potatocakes in forum New To JavaReplies: 9Last Post: 09-11-2008, 03:51 AM -
char to string
By kian_hong2000 in forum New To JavaReplies: 2Last Post: 08-25-2008, 02:51 PM -
Creating a Comparable object
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 08:38 PM -
Cannot convert from char to String error
By sondratheloser in forum New To JavaReplies: 1Last Post: 12-13-2007, 10:28 PM
Bookmarks