《騎士精神2》即將追加兩種全新武器
阿新 • • 發佈:2021-10-09
StringUtils位置:org.apache.commons.lang3.StringUtils
isEmpty和isBlank還是有些區別的:
isEmpty原始碼:
public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; }
isBlank原始碼:
/** * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p> * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is null, empty or whitespace * @since 2.0 * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */ public static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } return true; }
總結就是:isBlank是嚴格意義上的判空操作,而isEmpty無法判斷出來空格,例如:" "
更加詳細的說明可以參照:https://www.cnblogs.com/sealy321/p/10227131.html
官方API文件:https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html