- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are new methods added to the String class in Java 9?
A String is an immutable class in Java and there are two new methods added to the String class in Java 9. Those methods are chars() and codePoints(). Both of these two methods return the IntStream object.
1) chars():
The chars() method of String class can return a stream of int zero-extending the char values from this sequence.
Syntax
public IntStream chars()
Example
import java.util.stream.IntStream; public class StringCharsMethodTest { public static void main(String args[]) { String str = "Welcome to TutorialsPoint"; IntStream intStream = str.chars(); intStream.forEach(x -> System.out.printf("-%s", (char)x)); } }
Output
-W-e-l-c-o-m-e- -t-o- -T-u-t-o-r-i-a-l-s-P-o-i-n-t
2) codePoints():
The codePoints() method can return a stream of code point values from this sequence.
Syntax
public IntStream codePoints()
Example
import java.util.stream.IntStream; public class StringCodePointsMethodTest { public static void main(String args[]) { String str = "Welcome to Tutorix"; IntStream intStream = str.codePoints(); intStream.forEach(x -> System.out.print(new StringBuilder().appendCodePoint(x))); } }
Output
Welcome to Tutorix
- Related Articles
- What are the new methods added to an Optional class in Java 9?
- What are new methods have added to the Arrays class in Java 9?
- What are the new methods added to Process API in Java 9?
- What are the new features added to Stream API in Java 9?
- Which factory methods have added for collections in Java 9?
- What are Class/Static methods in Java?\n
- What are the conditions for Collection factory methods in Java 9?
- What are the changes of class loaders in Java 9?
- What are the rules for private methods in an interface in Java 9?
- What are the advantages of private methods in an interface in Java 9?
- What are the new features added in Python 3.10 version?
- What are the differences between class methods and class members in C#?
- What is New Versioning Scheme in Java 9?
- What are jQuery string methods?
- What are the important methods of the SQLException class?

Advertisements