Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2015 08:58
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public class SafeStringUtils {
public static boolean safeEquals(Object o1, Object o2) {
return o1 != null && o1.equals(o2);
public static boolean safeEqualsIgnoreCase(String s1, String s2) {
return s1 != null && s1.equalsIgnoreCase(s2);
public static boolean safeIsEmpty(String s) {
return s != null && s.isEmpty();
public static boolean safeContains(String s1, CharSequence cs) {
return !(s1 == null || cs == null) && s1.contains(cs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment