Logo

Programming-Idioms

History of Idiom 110 > diff from v84 to v85

Edit summary for version 85 by programming-idioms.org:
[Scala] +DemoURL

Version 84

2022-03-03, 22:41:51

Version 85

2022-03-03, 23:35:18

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
val blank = Option(s).forall(_.trim.isEmpty)
Code
val blank = Option(s).forall(_.trim.isEmpty)
Comments bubble
Use strip (Java 11) instead of trim for Unicode-awareness, or more simply use isBlank (Java 11)

Option(s) ensures that null is handled.
Comments bubble
Use strip (Java 11) instead of trim for Unicode-awareness, or more simply use isBlank (Java 11)

Option(s) ensures that null is handled.
Demo URL
https://replit.com/@ProgIdioms/SlateblueFrightenedService#main.scala