java布尔类型方法命名_Java布尔类

java布尔类型方法命名

The Boolean class is wrapper in class that is used to wrap a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean.

布尔类是类中的包装器,用于将原始类型boolean的值包装在对象中。 布尔类型的对象包含一个布尔类型的字段。

This class consists of many helping methods for converting a boolean to a String and a String to a boolean, as well as other constants and methods helpful while working with boolean.

此类包含许多用于将布尔值转换为String和将String转换为布尔值的帮助方法,以及在使用布尔值时有用的其他常量和方法。

This class is located into java.lang package and has following declaration.

此类位于java.lang包中,并具有以下声明。

宣言 (Declaration)

public final class Boolean extends Object implements Serializable, Comparable<Boolean>

Here we are explaining various methods of Boolean class and their example.

在这里,我们将解释布尔类的各种方法及其示例。

1. parseBoolean(String s) (1. parseBoolean(String s) )

The parseBoolean() method is used to parse the string argument as a boolean. It returns a boolean value either true or false. If the string argument is not null and is equal, ignoring case, to the string "true", it returns true.

parseBoolean()方法用于将字符串参数解析为布尔值。 它返回布尔值true或false。 如果字符串参数不为null,并且忽略大小写等于字符串“ true”,则返回true。

It takes a string argument that contains the boolean representation to be parsed.

它需要一个包含要解析的布尔表示形式的字符串参数。

句法 : (Syntax : )

public static boolean parseBoolean(String s)

例: (Example:)

In this example, we are parsing string arguments to the boolean type using the parseBoolean() method. This method returns true if the specified string can be parsed to boolean, false otherwise.

在此示例中,我们使用parseBoolean()方法将字符串参数解析为布尔类型。 如果可以将指定的字符串解析为布尔值,则此方法返回true,否则返回false。

public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        boolean obj1 = Boolean.parseBoolean("True"); 
    	boolean obj2 = Boolean.parseBoolean("False");
        boolean obj3 = Boolean.parseBoolean("StUdYtONiGhT"); 
        boolean obj4 = Boolean.parseBoolean("STUDYTONIGHT"); 
        boolean obj5 = Boolean.parseBoolean("studytonight"); 
        System.out.println(obj1); 
        System.out.println(obj2); 
        System.out.println(obj3); 
        System.out.println(obj4); 
        System.out.println(obj5);   
    } 
}
boolean-class-example

2. booleanValue() ( 2. booleanValue() )

The booleanValue() method is used to get boolean value of this Boolean object as a boolean primitive. It returns primitive type boolean value of the Boolean object. Declaration of this method is given below.

booleanValue()方法用于获取此布尔对象的布尔值作为布尔基元。 它返回布尔对象的原始类型布尔值。 该方法的声明在下面给出。

句法: (Syntax:)

public boolean booleanValue()

例: (Example:)

We are using booleanValue() method to get boolean value of the Boolean object. See the below example.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值