字符串为 null 或者内部字符全部为 ' ' '\t' '\n' '\r' 这四类字符时返回 true
(String str)
| 43 | * 字符串为 null 或者内部字符全部为 ' ' '\t' '\n' '\r' 这四类字符时返回 true |
| 44 | */ |
| 45 | public static boolean isBlank(String str) { |
| 46 | if (str == null) { |
| 47 | return true; |
| 48 | } |
| 49 | int len = str.length(); |
| 50 | if (len == 0) { |
| 51 | return true; |
| 52 | } |
| 53 | for (int i = 0; i < len; i++) { |
| 54 | switch (str.charAt(i)) { |
| 55 | case ' ': |
| 56 | case '\t': |
| 57 | case '\n': |
| 58 | case '\r': |
| 59 | //case '\b': |
| 60 | //case '\f': |
| 61 | break; |
| 62 | default: |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 判断字符串不为空返回true |
no test coverage detected