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.
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 delimeter ” ”
Geeks for Geeks
Example 2: To demonstrate add() with delimeter “,”
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- StringJoiner length() method in Java
- StringJoiner merge() method in Java
- StringJoiner toString() method in Java
- StringJoiner setEmptyValue() method in Java
- Java.util.StringJoiner in Java8
- When to use StringJoiner over StringBuilder?
- Java.util.ArrayList.add() Method in Java
- DelayQueue add() method in Java with Examples
- ArrayBlockingQueue add() method in Java
- LinkedList add() Method in Java
- HashSet add() Method in Java
- TreeSet add() Method in Java
- PriorityQueue add() Method in Java
- ArrayDeque add() Method in Java
- LinkedBlockingDeque add() method in Java
- GregorianCalendar add() Method in Java
- Vector add() Method in Java
- Stream.Builder add() method in Java
- IntStream.Builder add() method in Java
- PriorityBlockingQueue add() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.