Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java Example: Convert String Array to String http://www.chankok.com/java-convert-string-array-to-string/
package com.chankok.arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StringArrayToStringExample {
public static void main(String[] args) {
// Initial the string array
String[] stringArrays = {"abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz"};
// Example 1
StringBuilder builder = new StringBuilder();
for (String str : stringArrays) {
builder.append(str);
}
String string1 = builder.toString();
System.out.println("Example 1: " + string1);
// Example 2
String delimiter = "";
String string2 = String.join(delimiter, stringArrays);
System.out.println("Example 2: " + string2);
// Example 3
String string3 = Stream.of(stringArrays).collect(Collectors.joining());
System.out.println("Example 3: " + string3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment