Boolean优化字符串转换boolean的逻辑

This commit is contained in:
neko 2020-09-29 11:46:24 +08:00 committed by GitHub
parent 322c95fde2
commit 5d33c34574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@ import cn.hutool.core.convert.Convert;
public class BooleanUtil {
/** 表示为真的字符串 */
private static final String[] TRUE_ARRAY = { "true", "yes", "y", "t", "ok", "1", "on", "", "", "", "", ""};
private static final Set<String> TRUE_SET = new HashSet<>(Arrays.asList("true", "yes", "y", "t", "ok", "1", "on", "", "", "", "", ""));
/**
* 取相反值
@ -77,7 +77,7 @@ public class BooleanUtil {
public static boolean toBoolean(String valueStr) {
if (StrUtil.isNotBlank(valueStr)) {
valueStr = valueStr.trim().toLowerCase();
return ArrayUtil.contains(TRUE_ARRAY, valueStr);
return TRUE_SET.contains(valueStr);
}
return false;
}