-2

What's the best way to convert a string array to a delimiter separated string.

eg:

String[] arr = {"apple","orange","banana","round"}; -------> apple-orange-banana-round?

Community
  • 1
  • 1
Java User
  • 127
  • 3
  • 9

1 Answers1

0

You can use a StringBuffer or StringBuilder (StringBuffer is thread safe) to make this:

StringBuffer sb = new StringBuffer();
for(String s : arr){
    sb.append(s + "-");
}
sb.deleteCharAt(sb.length()-1);
return sb.toString();

Does this make sense to you?

Li Chao
  • 326
  • 2
  • 7