EN
Java - convert list to string
0 points
In this article, we would like to show you how to convert List to String in Java.
Quick solution:
xxxxxxxxxx
1
List<String> letters = Arrays.asList("A", "B", "C");
2
String result = String.join("", letters);
3
4
System.out.println(result); // ABC
In this example, we join items from fruits List using String join()
method with empty string (""
) as a separator.
xxxxxxxxxx
1
import java.util.Arrays;
2
import java.util.List;
3
4
public class Example {
5
6
public static void main(String[] args) {
7
List<String> letters = Arrays.asList("A", "B", "C");
8
9
String result = String.join("", letters);
10
11
System.out.println("List: " + letters); // [A, B, C]
12
System.out.println("String: " + result); // ABC
13
}
14
}
Output:
xxxxxxxxxx
1
List: [A, B, C]
2
String: ABC