The chars()
method is an instance method of the String
class. It returns an IntStream
that consists of the code point values of the characters in the given string. This method was added to the String
class in Java 9.
public IntStream chars()
This method has no parameters.
This method returns an IntStream
of char
values from the string.
import java.util.stream.IntStream;class Main {public static void main(String[] args) {// Define a stringString string = "hello-educative";// use the chars method to get a stream of char valuesIntStream codePointStream = string.chars();// convert the code points back to characters and print the outputcodePointStream.mapToObj(Character::toChars).forEach(System.out::println);}}
string
.chars()
method to get a stream of character values.