Java String comparison

N

nooobody

grz02 said:
Hi,

Im an experienced developer, but kinda new to Java...
Just want to know how you practically handle this one.

I have this code line (JSP):

String rqstUserid = (String)request.getParameter("userid");

Now I wanna check if this String is a non-empty, not-null string,
like:

if (rqstUserid != null) && (rqstUserid.length() > 0)
{ ... }

which looks terribly tedious syntax to me,
since you in some other language would just write something like:

if (rqstUserid<>"")
{ ... }

Is there some smarter way (=shorter syntax) to express the test above
in Java, i.e. when you have to account for null values?


you could use the org.apache.commons.validator.GenericValidator
isBlankOrNull(String) method.

But it may be more of a bother to do the import than doing it the way
you already have.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top