Logo

Programming-Idioms

History of Idiom 110 > diff from v59 to v60

Edit summary for version 60 by programming-idioms.org:
[Java] +DocURL for trim()

Version 59

2020-12-28, 22:41:21

Version 60

2021-01-20, 11:58:26

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==null || 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)
Doc URL
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#trim()
Demo URL
https://repl.it/@ProgIdioms/CheerfulAzureEnvironment
Demo URL
https://repl.it/@ProgIdioms/CheerfulAzureEnvironment