java - How to copy the entire values of array strings into a single string along with the empty spaces? -
i'm using eclipse, have argument on run configuration:
hello hello hello
apparently, it's on string[] args. there method can concatenate array values along empty spaces between them?
i have tried splicing arrays char arrays, used tostring method(garbage value reason), , stringbuilder. gives values not spaces itself. @@
you can use string.join method:
string[] arr = {"hello", "hello", "hello"}; system.out.println(string.join(" ", arr));
string#join available in java 8.
using stringbuilder:
stringbuilder sb = new stringbuilder(); string sep = ""; (string str : arr) { sb.append(sep); sb.append(str); sep = " "; } system.out.println(sb.tostring());
Comments
Post a Comment