VOOZH about

URL: https://www.geeksforgeeks.org/java/stringjoiner-add-method-in-java/

⇱ StringJoiner add() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

StringJoiner add() method in Java

Last Updated : 11 Jul, 2025

The add(CharSequence newElement) of StringJoiner adds a copy of the given CharSequence value as the next element of the StringJoiner value. If newElement is null, then "null" is added.
Syntax: 

public StringJoiner add(CharSequence newElement)


Parameters: This method takes a mandatory parameter newElement which is the element to be added.
Returns: This method returns a reference to this StringJoiner
Below programs illustrate the add() method:
Example 1: To demonstrate add() with delimiter " " 


Output: 
Geeks for Geeks

 

Example 2: To demonstrate add() with delimiter ","


Output: 
Geeks,for,Geeks

 
Comment