2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to use StringJoiner of Java 8 api.

How to use StringJoiner of Java 8 api.
userimage

Follow below example better understanding of StringJoinner :


public class StringJoinerUse {
    public static void main(String... args){
        StringJoiner sj = new StringJoiner(":");
        sj.add("deb");
        sj.add("ram");
        sj.add("sandip");
        sj.add("shruti");
        sj.add("indu");
        String result = sj.toString(); // aaa,bbb,ccc
        System.out.println(result); // Will print "deb":"ram":"sandip":"shruti":"indu"
    }
}

Answer is