How to join Multiple String Objects in Java 8

String.join() is introduced in Java8

We can use the String.join() method to join a number of String literals, String objects, String elements from an array, or String elements from List, Set or any collection because it accepts an Iterable

Example 

public class JoinString {
    
    public static void main(String[] args)
    {
        String java= String.join("|", "Cor Java", "JDBC", "JEE");
            System.out.println("Java: " + java);
    }
}

Output

Java: Cor Java|JDBC|JEE

Join List of String 

List<String> mobiles = Arrays.asList("Apple", "Samsung", "MI");
            String str = String.join(",", mobiles);
            System.out.println("List Mobiles : " + str);

Output

List Mobiles : Apple,Samsung,MI


Subscribe For Daily Updates

Flutter Questions
Android Questions