Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Monday Oct 8th 2018 by M S Sridhar

Language: Java, Expertise: Intermediate - See how to use StringJoiner to efficiently join multiple strings.

If you have multiple strings, you can use StringJoiner to join them efficiently.

import java.util.StringJoiner;

public class UsingStringJoiner
   public static void main(String args[])
      UsingStringJoiner usingStringJoiner = new UsingStringJoiner();
   private void proceed()
      StringJoiner stringArr = new StringJoiner(",", "{", "}");   
      //Here comma (,) is the delimiter and {} are the start and end suffix
        stringArr.add("Sun Microsystems");  
        stringArr.add("Database company");  
        stringArr.add("Software and Hardware");  



Expected output:

[root@mypc]# java UsingStringJoiner
{Sun Microsystems,Oracle,Database company,Software and Hardware}

Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved