Skip to content

Instantly share code, notes, and snippets.

@nathanchen
Created August 14, 2012 05:18
Show Gist options
  • Select an option

  • Save nathanchen/3346514 to your computer and use it in GitHub Desktop.

Select an option

Save nathanchen/3346514 to your computer and use it in GitHub Desktop.
JAVA - 查看String是否为null或者空
public static String nullToEmpty(@Nullable String string)
{
return (string == null) ? "" : string;
}
public static @Nullable String emptyToNull(@Nullable String string)
{
return isNullOrEmpty(string) ? null : string;
}
public static boolean isNullOrEmpty(@Nullable String string)
{
return string == null || string.length() == 0; // string.isEmpty() in Java6
}
@alanchenup
Copy link

很好 , 学习了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment