Best way to convert an ArrayList to a string

In Java 8 or later:

String listString = String.join(", ", list);

In case the list is not of type String, a joining collector can be used:

String listString = list.stream().map(Object::toString)
                        .collect(Collectors.joining(", "));

Leave a Comment