• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

List to String

 
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79415
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a regular expression and String#split to remove the hashcode?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic