For example, If I have an array
String[] myStringArray = new String[]{"x", "a", "r", "y"};
How do I make a singular string that is "xary"
For example, If I have an array
String[] myStringArray = new String[]{"x", "a", "r", "y"};
How do I make a singular string that is "xary"
You can iterate through all the elements of you array and append them in a StringBuilder. Get the resulting String calling toString().
With java 8, you could get a Stream from the array and use the reduce operation.
String s = Arrays.stream(myStringArray).reduce("", String::concat); //xary
The above java 8 solution has a worse complexity than using joining, so don't do that ! :)
You can manually concatenate it with a simple for loop like so
String myString;
for(int i = 0; i < myStringArray.length;i++)
myString + = myStringArray[i];
String[] myStringArray = new String[]{"x", "a", "r", "y"};
StringBuilder builder = new StringBuilder();
for(String s:myStringArray)
builder.append(s);
System.out.println(builder );