Java中的Boolean parseBoolean()方法及其示例

这个 parseBoolean() 方法 布尔类 是类的内置静态方法 JAVA朗布尔 用于将给定字符串转换为其布尔值。

null

语法:

Boolean.parseBoolean(String value)

参数: 它需要一个参数 价值 字符串类型,其中包含要转换为布尔值的值。

返回值: 它返回一个基本布尔值。它返回 符合事实的 如果给定值等于“真”,则忽略案例。否则它就会回来 错误的 .

下面是解释parseBoolean()方法的java代码:

例1:

class GeeksforGeeks {
// Driver method
public static void main(String[] args)
{
// string value
String value = "TrUe" ;
// parseBoolean using parse Boolean() method
boolean result = Boolean.parseBoolean(value);
// printing the result
System.out.println(result);
}
}


输出:

true

例2:

class GeeksforGeeks {
// Driver method
public static void main(String[] args)
{
// string value
String value = "true" ;
// parseBoolean using parse Boolean() method
boolean result = Boolean.parseBoolean(value);
// printing the result
System.out.println(result);
}
}


输出:

true

例3:

class GeeksforGeeks {
// Driver method
public static void main(String[] args)
{
// string value
String value = "gfg" ;
// parseBoolean using parse Boolean() method
boolean result = Boolean.parseBoolean(value);
// printing the result
System.out.println(result);
}
}


输出:

false

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享