StringJoiner length() method in Java Last Updated : 12 Dec, 2021 Comments Improve Suggest changes 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 length() 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 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 Month maxLength() method in Java The maxLength() method is a built-in method of the Month ENUM which is used to get the maximum length of this month in number of days. For example, February can have both 28 days and 29 days depending on whether this year is a leap year or not. Therefore, this method will return 29 for February as m 1 min read StringJoiner setEmptyValue() method in Java The setEmptyValue(CharSequence emptyValue) of StringJoiner sets the sequence of characters to be used when determining the string representation of this StringJoiner and no elements have been added yet, that is, when it is empty. A copy of the emptyValue parameter is made for this purpose. Note that 2 min read StringBuilder append() Method in Java In Java, the append() method of StringBuilder class is used to add data to the end of an existing StringBuilder object. It supports appending different data types like strings, integers, characters, and booleans by making it easy for dynamic string manipulation.Example 1: Here, we use the append() m 4 min read StringBuilder capacity() Method in Java In Java, the capacity() method of StringBuilder Class is used to return the current capacity of StringBuilder object. The capacity is the amount of storage available to insert new characters.Example 1: Here, we use the capacity() method to check the current capacity of the StringBuilder object.Java/ 2 min read Java String trim() Method The trim() method of the String class in Java is used to remove leading and trailing whitespace from a string. The Unicode value of the space character is "\u0020". It does not remove any whitespace in the middle of the string. This method returns a new string with the whitespace removed and leaves 4 min read Java StringBuffer capacity() Method In Java, the capacity() method is used in the StringBuilder and StringBuffer classes to retrieve the current capacity of the object. The capacity is the amount of space that has been allocated to store the string that can grow dynamically as needed.Example 1: The below Java program demonstrates the 3 min read Like