Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String manipulation

 
Udayan Kumar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Bye,
Uday
 
Venkata Narayana Reddy Pingala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

String array[] = {"False","No","Yes", "True"};
String afterApp="";
int i;
for(i=0;i<array.length;i++){
afterApp+=array[i]+" ";
}
for(i=i-2;i>=0;i--){
afterApp+=array[i]+" ";
}
System.out.println("After Append "+afterApp);


Regards,
Venkat
 
Ådne Brunborg
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic