Best way to verify string is empty or null

前端 未结 13 747
野的像风
野的像风 2020-12-14 15:30

i am sure this must have been asked before in different ways - as isEmptyOrNull is so common yet people implement it differently. but i have below curious query in terms of

相关标签:
13条回答
  • 2020-12-14 16:02

    Just to show java 8's stance to remove null values.

    String s = Optional.ofNullable(myString).orElse("");
    if (s.trim().isEmpty()) {
        ...
    }
    

    Makes sense if you can use Optional<String>.

    0 讨论(0)
提交回复
热议问题