VOOZH about

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

⇱ StringJoiner length() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

StringJoiner length() method in Java

Last Updated : 11 Jul, 2025

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 StringJoiner
Below programs illustrate the length() method:
Example 1: To demonstrate length() with delimiter " "


Output: 
StringJoiner: Geeks for Geeks
15

 

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


Output: 
StringJoiner: Geeks, for, Geeks, A, Computer, Portal
38

 
Comment