Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

Hi dear Friends, I want to change an array of string to a string in java?can anyone help me with?I do need your help. thanks!!!

OpenStudy (anonymous):

shadowfiend. can you help me with?

OpenStudy (anonymous):

Ahm.. I'm no Java-guy, but how about something like: String[] foo = {"some", "array", "of", "strings"}; String bar = ""; for(int i=0; i<foo.length; i++) bar += foo[i]; ??? Where foo[] is the array of strings you got and bar is the resulting string.. Hope that's what u wanted..?

OpenStudy (anonymous):

thanks!it is so nice!

OpenStudy (anonymous):

you're very welcome ;)

OpenStudy (anonymous):

MuH4hA's answer is correct; with a "foreach" loop (since Java 1.5) you can even save the i: final String[] foo = {"some", "array", "of", "strings"}; String bar = ""; for (String string : foo){ bar += string; } Note that if this is performance-critical code, you should be using a StringBuffer instead of concatenating strings.

OpenStudy (anonymous):

thank you both!you are all so kind!

OpenStudy (anonymous):

np

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!