This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting a string into list .

 
ashishk sharma
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic