Skip to content

Instantly share code, notes, and snippets.

@AmauryCarrade
Last active August 29, 2015 14:06
Show Gist options
  • Save AmauryCarrade/a0015b786874c868b1ca to your computer and use it in GitHub Desktop.
Save AmauryCarrade/a0015b786874c868b1ca to your computer and use it in GitHub Desktop.
getBooleanFromString
/**
* Returns a boolean from an entered string, or null if the string does not represent a boolean.
*
* "on", "yes", "y", "true" = true
* "off", "no", "n", "false" = false
*
* @param input the input text.
* @return true/false if the string is a boolean; null else.
*/
public Boolean getBooleanFromString(String input) {
if(input.equalsIgnoreCase("on") || input.equalsIgnoreCase("yes") || input.equalsIgnoreCase("y") || input.equalsIgnoreCase("true")) {
return true;
}
else if(input.equalsIgnoreCase("off") || input.equalsIgnoreCase("no") || input.equalsIgnoreCase("n") || input.equalsIgnoreCase("false")) {
return false;
}
else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment