Home » Java » Core Java » Benchmark for new string methods of Java 11

About Sezin Karli

Sezin Karli
Mathematics Engineer & Computer Scientist with a passion for software development. Avid learner for new technologies. Currently working as Senior Software Engineer at Sahibinden.com.

Benchmark for new string methods of Java 11

While I was checking what’s new in Java 11, I saw that there are several new methods for String class. So I wanted to do a microbenchmark with old way of doing things and by using new methods. These new methods are;

boolean isBlank()

String strip()

Stream lines()

isBlank() is tested agains trim().isEmpty(), strip() is tested agains trim() and lines() is tested agains split().

Here are the results:

BenchmarkScore
lines3252919
split2486539
strip18280130
trim18222362
isBlank25126454
trim + isEmpty19854156

Scores are based on operations per second so the more the better.

As you can see lines() is much faster than split().

strip() and trim() performed quite similar.

isBlank() outperformed trim() + empty().

You can check the benchmark code here.

Published on Java Code Geeks with permission by Sezin Karli, partner at our JCG program. See the original article here: benchmark for new string methods of java 11

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
St1mpy Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
St1mpy
Guest
St1mpy

Wow what aa useless benchmark