How to check spaces in Java

String selectedVal = "";
String selectedVal = "";

for (SelectItem item : filterItems) {
                selectedVal = item.getValue().toString();
                break;
            }

I'm getting selectedval = "" how to check this blank area in Java

I try to use if (! Selectedval. Equals ("") and if (! Selectedval. Isempty()) but the condition becomes true How do I check multiple spaces?

Solution

You can trim () strings before checking with isempty()

boolean isEmpty = myString.trim().isEmpty();

Beware of isempty (), which is only available after Java se 6

resources:

> javadoc – String. trim() > javadoc – String. isEmpty()

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>