Java StringBuffer chars() Method Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. Java // Java Program to demonstrate chars() method with a StringBuffer import java.util.stream.*; public class Chars { public static void main(String[] args) { // Create a StringBuffer object StringBuffer b = new StringBuffer("Java"); // Use chars() method to get an IntStream and // print each character's Unicode b.chars() .forEach(codePoint -> System.out.println("" + codePoint)); } } Output74 97 118 97 Syntax of chars() MethodIntStream chars()Parameter: NoneReturn 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. Java // Java Program to process numeric characters using chars() method import java.util.stream.*; public class Chars { public static void main(String[] args) { // Create a StringBuffer object // with numeric characters StringBuffer b = new StringBuffer("12345"); // Use chars() to iterate over the // characters and print them b.chars() .forEach(ch -> System.out.print((char) ch + " ")); } } Output1 2 3 4 5 Example 3: Here, we will use the chars() method with a StringBuffer containing both letters and digits. Java // Java Program to handle mixed content in a // StringBuffer using chars() method import java.util.stream.*; public class Chars { public static void main(String[] args) { // Create a StringBuffer object with // mixed characters StringBuffer b = new StringBuffer("swe217ami"); // Use chars() method to print // Unicode values of each character b.chars() .forEach(cp -> System.out.println("" + cp)); } } Output115 119 101 50 49 55 97 109 105 Comment More infoAdvertise with us Next Article Java String getBytes() Method J juhisrivastav Follow Improve Article Tags : Java Java-Strings java-StringBuffer Practice Tags : JavaJava-Strings Similar Reads StringBuffer getChars() method in Java with Examples The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method of StringBuffer class copies the characters starting at the index:srcBegin to index:srcEnd-1 from actual sequence into an array of char passed as parameter to function. The characters are copied into the array of char dst[] star 3 min read StringBuffer Class in Java The StringBuffer class in Java represents a sequence of characters that can be modified, which means we can change the content of the StringBuffer without creating a new object every time. It represents a mutable sequence of characters.Features of StringBuffer ClassThe key features of StringBuffer c 11 min read StringBuffer Class in Java The StringBuffer class in Java represents a sequence of characters that can be modified, which means we can change the content of the StringBuffer without creating a new object every time. It represents a mutable sequence of characters.Features of StringBuffer ClassThe key features of StringBuffer c 11 min read StringBuffer deleteCharAt() Method in Java with Examples The Java.lang.StringBuffer.deleteCharAt() is a built-in Java method which removes the char at the specified position in this sequence. So that the sequence is reduced by 1 char. Syntax: public StringBuffer deleteCharAt(int indexpoint) Parameters : The method accepts a single parameter indexpoint of 2 min read Java String getBytes() Method In Java, the getBytes() method of the String class converts a string into an array of bytes. This method is useful for encoding the strings into binary format, which can then be used for file I/O, network transmission, or encryption. It can be used with the default character set or with a specified 2 min read StringBuffer toString() method in Java with Examples The toString() method of StringBuffer class is the inbuilt method used to returns a string representing the data contained by StringBuffer Object. A new String object is created and initialized to get the character sequence from this StringBuffer object and then String is returned by toString(). Sub 2 min read Like