File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes String manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String manipulation" Watch "String manipulation" New topic

String manipulation

Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi All,

Currently I am trying to do a string manipulation where in a for loop I want to append new pieces of String in front of and at the end of the existing string.
So the output should be something like this.

I have a String array = {"False","No","Yes", "True};

So all the initial values should appear twice like shown below & the last value should be shown only once.
False No Yes True Yes No False

Do let me know how to go about the same

Venkata Narayana Reddy Pingala

Joined: Jan 16, 2007
Posts: 3

Check this code. it will give you waht do you want:::

String array[] = {"False","No","Yes", "True"};
String afterApp="";
int i;
afterApp+=array[i]+" ";
afterApp+=array[i]+" ";
System.out.println("After Append "+afterApp);

Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Check out the StringBuilder class, added in Java 5. It is basically a mutable String class, and allows you to avoid iterate twice through the array.
[ January 16, 2007: Message edited by: �dne Brunborg ]

Entia non sunt multiplicanda praeter necessitatem
I agree. Here's the link:
subject: String manipulation
It's not a secret anymore!