In Java, String is an immutable class and two new methods were added to the String class in Java 9. These two methods are chars() and codePoints(). Both methods return IntStream objects.
The chars() method of the String class can return an int stream of zero-extended character values from the sequence. The Chinese translation of
<strong>public IntStream chars()</strong>
import java.util.stream.IntStream; public class StringCharsMethodTest { public static void main(String args[]) { String str = "Welcome to TutorialsPoint"; IntStream intStream = str.<strong>chars()</strong>; intStream.forEach(x -> System.out.printf("-%s", (char)x)); } }
<strong>-W-e-l-c-o-m-e- -t-o- -T-u-t-o-r-i-a-l-s-P-o-i-n-t </strong>
The codePoints() method can return a stream of code point values from this sequence. The Chinese translation of
<strong>public IntStream codePoints()</strong>
import java.util.stream.IntStream; public class StringCodePointsMethodTest { public static void main(String args[]) { String str = "Welcome to Tutorix"; IntStream intStream = str.<strong>codePoints()</strong>; intStream.forEach(x -> System.out.print(new StringBuilder().<strong>appendCodePoint</strong>(x))); } }
<strong>Welcome to Tutorix</strong>
The above is the detailed content of What new methods have been added to String class in Java 9?. For more information, please follow other related articles on the PHP Chinese website!