StringJoiner length() method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The length() of StringJoiner is used to find out the length of the StringJoiner in characters. It returns the length of the String representation of this StringJoiner. Note that if no add methods have been called, then the length of the String representation (either prefix + suffix or emptyValue) will be returned. The value should be equivalent to toString().length().Syntax: public int length() Returns: This method returns the length of the current value of StringJoinerBelow programs illustrate the length() method:Example 1: To demonstrate length() with delimiter " " Java // Java program to demonstrate // length() method of StringJoiner import java.util.StringJoiner; public class GFG { public static void main(String[] args) { // Creating StringJoiner with delimiter " " StringJoiner str = new StringJoiner(" "); // Adding elements in the StringJoiner str.add("Geeks"); str.add("for"); str.add("Geeks"); // Print the StringJoiner System.out.println("StringJoiner: " + str.toString()); // Printing the length of str // using length() method System.out.println(str.length()); } } Output: StringJoiner: Geeks for Geeks 15 Example 2: To demonstrate length() with delimiter ", " Java // Java program to demonstrate // length() method of StringJoiner import java.util.StringJoiner; public class GFG { public static void main(String[] args) { // Creating StringJoiner with delimiter "" StringJoiner str = new StringJoiner(", "); // Adding elements in the StringJoiner str.add("Geeks"); str.add("for"); str.add("Geeks"); str.add("A"); str.add("Computer"); str.add("Portal"); // Print the StringJoiner System.out.println("StringJoiner: " + str.toString()); // Printing the length of str // using length() method System.out.println(str.length()); } } Output: StringJoiner: Geeks, for, Geeks, A, Computer, Portal 38 Comment More infoAdvertise with us Next Article StringJoiner toString() method in Java C code_r Follow Improve Article Tags : Java Java - util package Java-Functions Java-StringJoiner Practice Tags : Java Similar Reads Java String length() Method String length() method in Java returns the length of the string. In this article, we will see how to find the length of a string using the String length() method.Example:Javaclass Geeks { public static void main(String[] args){ String s1 = "abcd"; System.out.println(s1.length()); String s2 = ""; Sys 2 min read StringJoiner add() method in Java 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 newElem 1 min read StringJoiner add() method in Java 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 newElem 1 min read Month length() method in Java The length() method is a built-in method of the Month ENUM which is used to get the number of days in this month instance. The number of days in a month can be 28, 30 or 31. Number of days in February in a leap year is 29. This method accepts a boolean flag variable which indicates whether this Year 1 min read StringJoiner toString() method in Java The toString() of StringJoiner is used to convert StringJoiner to String. It returns the current value, consisting of the prefix, the values added so far separated by the delimiter, and the suffix, unless no elements have been added in which case, the prefix + suffix or the emptyValue characters are 2 min read StringJoiner toString() method in Java The toString() of StringJoiner is used to convert StringJoiner to String. It returns the current value, consisting of the prefix, the values added so far separated by the delimiter, and the suffix, unless no elements have been added in which case, the prefix + suffix or the emptyValue characters are 2 min read Like