Is it possible to simply check a java String argument is present and return a boolean true or return false if the argument is of a Null value?

Recommended Answers

All 6 Replies

boolean isNull = stringArg == null;

boolean isNull = stringArg == null;

Thank you for you response would the code below be an acceptable way of incorporating this, I'm fairly new to java and tend to over lengthen my code. Thank you again


[
public boolean myWord(String word)
{
boolean isNull = word== null;
if (isNull = false)
{
return false;
}
else
{
return true;
}
}
]

Your logic looks OK (except you need == to test for equality, not just =), but pretty lengthy and redundant - how about:

public boolean myWordIsNull(String word) {
   return word == null;
}

Your logic looks OK (except you need == to test for equality, not just =), but pretty lengthy and redundant - how about:

public boolean myWordIsNull(String word) {
   return word == null;
}

end quote.

If I used this am I right it would return true if Null was found
if I wanted false if Null was found but true if a String was found would this adaption be okay. - My lack of experiance shows in the comparisons of the texts - thank you

public boolean myWordIsNull(String word) {
   return word != null;
}

Yup, that looks good. I would change the name of the method to something like myWordIsNotNull.

Thank youfor your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.