Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
953 views
in Technique[技术] by (71.8m points)

string - Difference between isEmpty() and isBlank() Method in java 11

Java 11 has added A new instance method isBlank() to java.lang.String class.

What's the basic difference between the existing isEmpty and newly added isBlank() method?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

isEmpty()

The java string isEmpty() method checks if this string is empty. It returns true, if the length of the string is 0 otherwise false e.g.

System.out.println("".isEmpty()); // Prints - True
System.out.println(" ".isEmpty()); //Prints - False 

Java 11 - isBlank()

The new instance method java.lang.String.isBlank() returns true if the string is empty or contains only white space, where whitespace is defined as any codepoint that returns true when passed to Character#isWhitespace(int).

boolean blank = string.isBlank();

Before Java 11

boolean blank = string.trim().isEmpty();

After Java 11

boolean blank = string.isBlank();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...