org.apache.commons.lang3.StringUtils类的2个方法区别

查看源码

  1. //isEmpty
  2. public static boolean isEmpty(final CharSequence cs) {
  3. return cs == null || cs.length() == 0;
  4. }
  5. //isBlank
  6. public static boolean isBlank(final CharSequence cs) {
  7. int strLen;
  8. if (cs == null || (strLen = cs.length()) == 0) {
  9. return true;
  10. }
  11. for (int i = 0; i < strLen; i++) {
  12. if (Character.isWhitespace(cs.charAt(i)) == false) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }

通过源码分析,isnotempty不能判断空白字符串

总结

一般使用isBlank