VOOZH about

URL: https://www.geeksforgeeks.org/java/java-stringbuffer-chars-method/

⇱ Java StringBuffer chars() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java StringBuffer chars() Method

Last Updated : 23 Jul, 2025

In Java, the chars() method of the StringBuffer class converts the characters in the StringBuffer to an IntStream. This method is useful for iterating over, processing, or filtering characters in a StringBuffer.

Example 1: Here, we will iterate over characters by using the chars() method and it will print the Unicode code points of each character in a StringBuffer object.


Output
74
97
118
97

Syntax of chars() Method

IntStream chars()

  • Parameter: None
  • Return Type: IntStream: It returns an IntStream representing the Unicode code points of the characters in the StringBuffer.

Example 2: Here, we will use the chars() method to process numeric characters in the StringBuffer.


Output
1 2 3 4 5 

Example 3: Here, we will use the chars() method with a StringBuffer containing both letters and digits.


Output
115
119
101
50
49
55
97
109
105
Comment
Article Tags: