aspose file tools*
The moose likes Beginning Java and the fly likes Converting a string into list . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Converting a string into list ." Watch "Converting a string into list ." New topic
Author

Converting a string into list .

ashishk sharma
Greenhorn

Joined: Oct 23, 2008
Posts: 11
HI

i have a string as input like " String s=""ABC-CDF" + "EFG-HIJ" + "KLM_NMK"+ (might me some more string at run time.)

I like to add commas between the string which is defined above.;

finally i want this string into a list like :

{ABC,CDF,EFG,HIJ,KLM,NMK}



so can you please suggest me how can i do this in java.....

please provide me the code snippets if you have ....its urgent

thanks in advance.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3849

First this is not related to Servlet, moderator will move this to an more appropriate forum. To get you started have a look at Scanner class from the API


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
First this is not related to Servlet, moderator will move this to an more appropriate forum.

Vijitha, what do you mean by not related to servlet, this is not Servlet forum, this is Java beginner's forum, this post is in appropriate place!

i have a string as input like " String s=""ABC-CDF" + "EFG-HIJ" + "KLM_NMK"+ (might me some more string at run time.)


Here each three letters are separated by '-' and '_' , does this separator change for each string or its '-' for all?
This needs little logic that's it! Try substring() its easy.


SCJP 1.5
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3849

Bharadwaj Adepu wrote:Vijitha, what do you mean by not related to servlet, this is not Servlet forum, this is Java beginner's forum, this post is in appropriate place!


Now it is in the right place. Check this where it was originally posted. (Luckily new forum software shows the moved topics in the original forum by curved arrow, so I could prove that to you . It wasn't in the old forum as I remember)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Split with an appropriate regular expression and the String#split method and pass the resultant array to a List implementation constructor, possibly via the Arrays#asList method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting a string into list .