String转boolean类型方法
采用boolean b1 = Boolean.parseBoolean(字符串)
把字符串转布尔类型,代码如下:
package;
public class MyTest {
public static void main(String[] args) {
String b = "true";
boolean b1 = Boolean.parseBoolean(b);
System.out.println("b1 = " + b1);
}
}
输出结果: b1 = true
也可以用"boolean b1 = true".equals(字符串) ? true: false;
把字符串转布尔类型,代码如下:
package;
public class MyTest {
public static void main(String[] args) {
String b = "true";
boolean b1 = "true".equals(b) ? true: false;
System.out.println("b1 = " + b1);
}
}
输出结果: b1 = true