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:
List<String> letters = Arrays.asList("A", "B", "C");
String result = String.join("", letters);
System.out.println(result); // ABC
Practical example
In this example, we join items from fruits List using String join()
method with empty string (""
) as a separator.
import java.util.Arrays;
import java.util.List;
public class Example {
public static void main(String[] args) {
List<String> letters = Arrays.asList("A", "B", "C");
String result = String.join("", letters);
System.out.println("List: " + letters); // [A, B, C]
System.out.println("String: " + result); // ABC
}
}
Output:
List: [A, B, C]
String: ABC