org.apache.commons.lang3包中的isEmpty和isBlank
主要为了区分一下empty和blank的用法,先看源码:
isEmpty
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public static boolean isEmpty(CharSequence cs) { 2 return cs == null || cs.length() == 0; 3 }
isBlank
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public static boolean isBlank(CharSequence cs) { 2 int strLen; 3 if (cs != null && (strLen = cs.length()) != 0) { 4 for(int i = 0; i < strLen; ++i) { 5 if (!Character.isWhitespace(cs.charAt(i))) { 6 return false; 7 } 8 } 9 10 return true; 11 } else { 12 return true; 13 } 14 }
两者都是判断字符串是否为空的方法,区别是对空格字符的判断。举个例子
对于isEmpty," "不是空,
对于isBlank," "是空。
当你能轻松进入的时候,你就该明白,不是你厉害,只是对方能够容忍你的渺小。——保尔.柯察金