• 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

Convert String to ArrayList

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have requirement where the user will paste these codes in the text area from the front end and I need to convert this string to Arraylist, can any body please help me with this..
-----------
222222
333333
444444
555555
666666
777777
888888
999999
-----------

This whole numbers come as String to and need to convert to Arraylist, i treid some ways but iam not successfull.
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the API for String.split() and Arrays.asList().
 
shailesh kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Steve,
I used the same methods..but here is the result..

String[] outPut = null;

outPut = barcodePaste.split("/n");

// barcodePaste is coming from front end as String

But when I do outPut[1], it returns Index out bound exception, If I call outPut[0] it returns the entire string again. Its not adding to the array on index by index, how do I do that??
 
Steve Morrow
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The newline character is "\n".
 
shailesh kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ! thanks Steve !!, that was really silly mistake...
 
reply
    Bookmark Topic Watch Topic
  • New Topic