Logo

Programming-Idioms

History of Idiom 110 > diff from v51 to v52

Edit summary for version 52 by programming-idioms.org:
[Java] null check

Version 51

2020-08-09, 18:01:22

Version 52

2020-09-30, 09:01:38

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Code
boolean blank = s.trim().isEmpty();
Code
boolean blank = s==null || s.trim().isEmpty();
Comments bubble
Use strip (Java 11) instead of trim for Unicode-awareness, or more simply use isBlank (Java 11)
Comments bubble
Use strip (Java 11) instead of trim for Unicode-awareness, or more simply use isBlank (Java 11)