Skip to content

Instantly share code, notes, and snippets.

@benkn
Last active December 11, 2015 11:58
Show Gist options
  • Save benkn/4597460 to your computer and use it in GitHub Desktop.
Save benkn/4597460 to your computer and use it in GitHub Desktop.
Check if the given String is not null or has a value other than whitespace.
/**
* Check that the given String is not null and has a value other than
* whitespace.
*
* {@code
* hasValue(null) = false
* hasValue("") = false
* hasValue(" ") = false
* hasValue("bob") = true
* hasValue(" bob ") = true
* }
*
* @param input String
* @return true if the input has a value, and false if not.
*/
public static boolean hasValue(String input) {
if ( input != null && input.trim().length() > 0 ) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment