java的boolean与string类型转换Boolean.valueOf(“TRUE”)==true//此处的参数true忽略⼤⼩写
其他都是false
直接上源码:
/**
* Returns a {@code Boolean} with a value represented by the
* specified string.  The {@code Boolean} returned represents a
* true value if the string argument is not {@code null}
* and is equal, ignoring case, to the string {@code "true"}.
*
* @param  s  a string.
java valueof* @return  the {@code Boolean} value represented by the string.
*/
public static Boolean valueOf(String s) {
return toBoolean(s) ? TRUE : FALSE;
}
private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}
熟悉C语⾔的⼈都知道,C⾥⾯0是false,其余的⾮零数值都是true
java⾥⾯也有⼀个⽅法⽤来实现从string类型转到boolean类型,但是更加简单粗暴,Boolean.valueOf(“true”)//此处的参数true忽略⼤⼩写
其他的值都是false,详见上⾯源码