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,详见上⾯源码
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论