Logo

Programming-Idioms

History of Idiom 110 > diff from v80 to v81

Edit summary for version 81 by programming-idioms.org:
[Java] Better demo link (shows code)

Version 80

2022-02-24, 18:07:18

Version 81

2022-02-24, 18:08:02

Idiom #110 Check if string is blank

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

Idiom #110 Check if string is blank

Set the boolean blank to true if the 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()
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://replit.com/@ProgIdioms/CheerfulAzureEnvironment#Main.java