dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Oct 8, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Using StringJoiner to Join 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();
      usingStringJoiner.proceed();
   }
   
   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("Oracle");  
        stringArr.add("Database company");  
        stringArr.add("Software and Hardware");  
                  
        System.out.println(stringArr);        
   }

}

/*

Expected output:

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

*/ 
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date