aspose file tools*
The moose likes Java in General and the fly likes List to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "List to String" Watch "List to String" New topic
Author

List to String

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

Hi I am stuck in a palce where the values are in a List and i have to save this value into a string

I tried list.toString(); //not give the string i am looking 4 means it includes hashcode also
(String) list.get(index) //gives me a class cast exception...

Any other way out to solve this problemo...

Kaustubh


No Kaustubh No Fun, Know Kaustubh Know Fun..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38405
    
  23
Use a regular expression and String#split to remove the hashcode?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4366
    
    8

You need to get the entire list as a String? Or just some of the values?

list.get(index).toString()
will convert any of the values to a String (whether that's useful will depend on what sort of objects they are).
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
A code sample would be nice

Not sure where're you getting that hash code from.


prints out: [octopus, fish, shark]

If you have objects in that list of your own creation, override toString method of your class.


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

thanks guys for the knowledge actually using user's and little mine apporoch I come up with this code...


List list= mhome.fetchMsgIdentifierByMessageId(5);
Object obj[] = (Object[]) list.get(0);
String s1=obj[0].toString();

it really works

Thanks
Kaustubh
 
jQuery in Action, 2nd edition
 
subject: List to String