| Author |
Turn an String array all into one String?
|
Ben Jass
Ranch Hand
Joined: Sep 25, 2010
Posts: 76
|
|
Ok lets say I have a string array like so:
String[] example = {"Poopy", "55","coolio");
How could I change this, all into one String like so:
String whatIWant = "Poopy55coolio";
I appreciate it.
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
Start with an empty whatIWant String (""). Using a for loop, iterate through each of the Strings in your array and add them to whatIWant. Please respond if you need more advice.
|
 |
Ben Jass
Ranch Hand
Joined: Sep 25, 2010
Posts: 76
|
|
Well I was thinking that, but if I did this
for (int counter = 0; counter < example.length; counter++) {
whatIWant = example[counter];
}
Doesn't it just change the example every time until it reaches the ending length.
So the outcome would be:
whatIWant = "coolio";
Oh wait...would I do this:
whatIWant += example[counter];
?
|
 |
Greg Brannon
Bartender
Joined: Oct 24, 2010
Posts: 530
|
|
Try
whatIWant += example[counter];
|
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2928
|
|
|
You can try toString method of java.util.Arrays class.
|
Mohamed Sanaulla | My Blog
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Don't concatenate the Strings but use a StringBuilder.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
 |
|
|
subject: Turn an String array all into one String?
|
|
|