string join java 8

Solutions on MaxInterview for string join java 8 by the best coders in the world

showing results for - "string join java 8"
Maverick
21 Feb 2017
1public class main {  
2    public static void main(String args[]) {
3        String[] wordsToJoin = new String[] {"Hi", "there", "<3"};
4     	// first argument is the delimeter
5	    String example1 = String.join(", ", wordsToJoin);
6      
7      	// can also do this instead
8        String example2 = String.join("^ ","Hi","there","<3");  
9	
10        System.out.println(example1; // Hi, there, <3
11	    System.out.println(example2); // Hi^there^<3
12    }
13}