Question:
How can I take in a simplified way several Strings from an ArrayList and join them in just one variable of type String? I'm new to Java and I'm having trouble completing this change in a simplified way, avoiding unnecessary and long lines of code.
List<String> fields_list = new ArrayList<String>();
Saída: ["Campo1, Campo2, Campo3"]
My String variable should look like this:
String fields = "Campo1 Campo2 Campo3";
Answer:
Use o método join() da classe String:
String fields = String.join(" ", fields_list);
Note: Requires JAVA 8