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 { Output Java: Cor Java|JDBC|JEE Join List of String List<String> mobiles = Arrays.asList("Apple", "Samsung", "MI"); Output List Mobiles : Apple,Samsung,MI
public static void main(String[] args)
{
String java= String.join("|", "Cor Java", "JDBC", "JEE");
System.out.println("Java: " + java);
}
}
String str = String.join(",", mobiles);
System.out.println("List Mobiles : " + str);
How to Fetch System UUID with Java Program?
How to create Arraylist from Array in Java
What is a Collection ?
How to Convert a Map to a List in Java Example
What is Difference Between "==" and "equals" method in Java
How to split a string in Java
How to convert ArrayList to Array in Java
What is Java Collections Framework?
How to Sort ArrayList of Object Type in Java?
Java Thread - How to create Threads in Java?
How to join Multiple String Objects in Java 8
What is difference between HashMap and HashSet in Java