Using StringJoiner to Join Strings

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}*/ 
See also  Java Developer Jobs: Your Guide to Landing the Perfect Position in 2024

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist