aspose file tools*
The moose likes Servlets and the fly likes saprating strings with commas one by one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "saprating strings with commas one by one" Watch "saprating strings with commas one by one" New topic
Author

saprating strings with commas one by one

Arun M'Purushothaman
Greenhorn

Joined: Mar 14, 2003
Posts: 16
I need to get a single string from many strings which should be connected with commas. how i can do it with java?


Nothing is impossible, even the word impossible says 'i m possible'.
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Try using a StringBuffer and then loop through the Strings that you wish to concetnate passing it to the append() method on the StringBuffer.


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Rohit Ahuja
Ranch Hand

Joined: Oct 04, 2001
Posts: 121
Andy,
Give him the code dear.
Okie here u go,
Assuming i have a 100 strings in a String array arr.
StringBuffer stringbuffer = new StringBuffer(200);
for(int i = 0;i < arr.length; i++ )
{
if(!String.valueOf( arr[i] ).equals("null"))
{
if(i != 0)stringbuffer.append(",");

stringbuffer.append( arr[i] );
}
}
System.out.println( stringbuffer );
Give it a shot dude.Tell me if it doesnt work.Try some R&D okie?? I havent tried compiling and runing the program.


Face Off.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: saprating strings with commas one by one