Created
August 14, 2012 05:18
-
-
Save nathanchen/3346514 to your computer and use it in GitHub Desktop.
JAVA - 查看String是否为null或者空
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
很好 , 学习了