File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Convert String to ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert String to ArrayList" Watch "Convert String to ArrayList" New topic
Author

Convert String to ArrayList

shailesh kumar
Ranch Hand

Joined: Jul 18, 2005
Posts: 36
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.
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Check the API for String.split() and Arrays.asList().
shailesh kumar
Ranch Hand

Joined: Jul 18, 2005
Posts: 36
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

Joined: May 22, 2003
Posts: 657

The newline character is "\n".
shailesh kumar
Ranch Hand

Joined: Jul 18, 2005
Posts: 36
Oh ! thanks Steve !!, that was really silly mistake...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert String to ArrayList