Java Program to Call Add() Method in a Cascaded Manner From an Object of Stringjoiner Class

You are currently viewing Java Program to Call Add() Method in a Cascaded Manner From an Object of Stringjoiner Class

Java program to call add() method in a cascaded manner from an object of StringJoiner class

// Java program to call add() method in a cascaded manner 
// from an object of StringJoiner class

import java.util.*;

public class Main {
  public static void main(String[] args) {
    StringJoiner str = new StringJoiner(",");

    str.add("ABC").add("LMN").add("PQR").add("XYZ");

    System.out.println("Constructed String is: '" + str + "'");
  }
}

Output

Constructed String is: 'ABC,LMN,PQR,XYZ'

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply