Java – How to join List String with commas

In Java, we can use String.join(“,”, list) to join a List String with commas. 1. Java 8 1.1 String.join JavaStringExample1.java package com.mkyong; import java.util.Arrays; import java.util.List; public class JavaStringExample1 { public static void main(String[] args) { List<String> list = Arrays.asList("a","b","c"); String result = String.join(",", list); System.out.println(result); } } Output a,b,c 1.2 Stream Collectors.joining JavaStringExample2.java package …

Read more

Java – Convert comma-separated String to a List

Java examples to show you how to convert a comma-separated String into a List and vice versa. 1. Comma-separated String to List TestApp1.java package com.mkyong.utils; import java.util.Arrays; import java.util.List; public class TestApp1 { public static void main(String[] args) { String alpha = "A, B, C, D"; //Remove whitespace and split by comma List<String> result = …

Read more