# Boolean

public final class **Boolean** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Serializable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Serializable.html) [Comparable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html)\<[Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html)\> The Boolean class wraps a value of the primitive type
`boolean` in an object. An object of type
`Boolean` contains a single field whose type is
`boolean`.


In addition, this class provides many methods for
converting a `boolean` to a `String` and a
`String` to a `boolean`, as well as other
constants and methods useful when dealing with a
`boolean`.

### Field Summary

|---|---|---|
| public static final [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) | [FALSE](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#FALSE) | The `Boolean` object corresponding to the primitive value `false`. |
| public static final [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) | [TRUE](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#TRUE) | The `Boolean` object corresponding to the primitive value `true`. |
| public static final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<[Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html)\> | [TYPE](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#TYPE) | The Class object representing the primitive type boolean. |

### Public Constructor Summary

|---|---|
|   | [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#Boolean(boolean))(boolean value) Allocates a `Boolean` object representing the `value` argument. |
|   | [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#Boolean(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) Allocates a `Boolean` object representing the value `true` if the string argument is not `null` and is equal, ignoring case, to the string `"true"`. |

### Public Method Summary

|---|---|
| boolean | [booleanValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#booleanValue())() Returns the value of this `Boolean` object as a boolean primitive. |
| static int | [compare](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#compare(boolean,%20boolean))(boolean x, boolean y) Compares two `boolean` values. |
| int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#compareTo(java.lang.Boolean))([Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) b) Compares this `Boolean` instance with another. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Returns `true` if and only if the argument is not `null` and is a `Boolean` object that represents the same `boolean` value as this object. |
| static boolean | [getBoolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#getBoolean(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Returns `true` if and only if the system property named by the argument exists and is equal to the string `"true"`. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#hashCode())() Returns a hash code for this `Boolean` object. |
| static int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#hashCode(boolean))(boolean value) Returns a hash code for a `boolean` value; compatible with `Boolean.hashCode()`. |
| static boolean | [logicalAnd](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#logicalAnd(boolean,%20boolean))(boolean a, boolean b) Returns the result of applying the logical AND operator to the specified `boolean` operands. |
| static boolean | [logicalOr](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#logicalOr(boolean,%20boolean))(boolean a, boolean b) Returns the result of applying the logical OR operator to the specified `boolean` operands. |
| static boolean | [logicalXor](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#logicalXor(boolean,%20boolean))(boolean a, boolean b) Returns the result of applying the logical XOR operator to the specified `boolean` operands. |
| static boolean | [parseBoolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#parseBoolean(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) Parses the string argument as a boolean. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#toString())() Returns a `String` object representing this Boolean's value. |
| static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#toString(boolean))(boolean b) Returns a `String` object representing the specified boolean. |
| static [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) | [valueOf](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#valueOf(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) Returns a `Boolean` with a value represented by the specified string. |
| static [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) | [valueOf](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#valueOf(boolean))(boolean b) Returns a `Boolean` instance representing the specified `boolean` value. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.lang.Comparable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html)

|---|---|
| abstract int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html#compareTo(T))([Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) o) Compares this object with the specified object for order. |

## Fields

#### public static final Boolean
**FALSE**

The `Boolean` object corresponding to the primitive
value `false`.

#### public static final Boolean
**TRUE**

The `Boolean` object corresponding to the primitive
value `true`.

#### public static final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<[Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html)\>
**TYPE**

The Class object representing the primitive type boolean.

## Public Constructors

#### public
**Boolean**
(boolean value)

Allocates a `Boolean` object representing the
`value` argument.

**Note: It is rarely appropriate to use this constructor.
Unless a *new* instance is required, the static factory
`https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#valueOf(boolean)` is generally a better choice. It is
likely to yield significantly better space and time performance.**

##### Parameters

| value | the value of the `Boolean`. |
|---|---|

#### public
**Boolean**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s)

Allocates a `Boolean` object representing the value
`true` if the string argument is not `null`
and is equal, ignoring case, to the string `"true"`.
Otherwise, allocate a `Boolean` object representing the
value `false`. Examples:


`new Boolean("True")` produces a `Boolean` object
that represents `true`.  

`new Boolean("yes")` produces a `Boolean` object
that represents `false`.

##### Parameters

| s | the string to be converted to a `Boolean`. |
|---|---|

## Public Methods

#### public boolean
**booleanValue**
()

Returns the value of this `Boolean` object as a boolean
primitive.

##### Returns

- the primitive `boolean` value of this object.

#### public static int
**compare**
(boolean x, boolean y)

Compares two `boolean` values.
The value returned is identical to what would be returned by:

```
    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
 
```

<br />

##### Parameters

| x | the first `boolean` to compare |
| y | the second `boolean` to compare |
|---|---|

##### Returns

- the value `0` if `x == y`; a value less than `0` if `!x && y`; and a value greater than `0` if `x && !y`

#### public int
**compareTo**
([Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html) b)

Compares this `Boolean` instance with another.

##### Parameters

| b | the `Boolean` instance to be compared |
|---|---|

##### Returns

- zero if this object represents the same boolean value as the argument; a positive value if this object represents true and the argument represents false; and a negative value if this object represents false and the argument represents true

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the argument is `null` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html`

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj)

Returns `true` if and only if the argument is not
`null` and is a `Boolean` object that
represents the same `boolean` value as this object.

##### Parameters

| obj | the object to compare with. |
|---|---|

##### Returns

- `true` if the Boolean objects represent the same value; `false` otherwise.

#### public static boolean
**getBoolean**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Returns `true` if and only if the system property
named by the argument exists and is equal to the string
`"true"`. (Beginning with version 1.0.2 of the
Java^TM^ platform, the test of
this string is case insensitive.) A system property is accessible
through `getProperty`, a method defined by the
`System` class.


If there is no property with the specified name, or if the specified
name is empty or null, then `false` is returned.

##### Parameters

| name | the system property name. |
|---|---|

##### Returns

- the `boolean` value of the system property.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | for the same reasons as `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/System.html#getProperty(java.lang.String)` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/System.html#getProperty(java.lang.String)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/System.html#getProperty(java.lang.String,%20java.lang.String)`

#### public int
**hashCode**
()

Returns a hash code for this `Boolean` object.

##### Returns

- the integer `1231` if this object represents `true`; returns the integer `1237` if this object represents `false`.

#### public static int
**hashCode**
(boolean value)

Returns a hash code for a `boolean` value; compatible with
`Boolean.hashCode()`.

##### Parameters

| value | the value to hash |
|---|---|

##### Returns

- a hash code value for a `boolean` value.

#### public static boolean
**logicalAnd**
(boolean a, boolean b)

Returns the result of applying the logical AND operator to the
specified `boolean` operands.

##### Parameters

| a | the first operand |
| b | the second operand |
|---|---|

##### Returns

- the logical AND of `a` and `b`

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/BinaryOperator.html`

#### public static boolean
**logicalOr**
(boolean a, boolean b)

Returns the result of applying the logical OR operator to the
specified `boolean` operands.

##### Parameters

| a | the first operand |
| b | the second operand |
|---|---|

##### Returns

- the logical OR of `a` and `b`

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/BinaryOperator.html`

#### public static boolean
**logicalXor**
(boolean a, boolean b)

Returns the result of applying the logical XOR operator to the
specified `boolean` operands.

##### Parameters

| a | the first operand |
| b | the second operand |
|---|---|

##### Returns

- the logical XOR of `a` and `b`

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/BinaryOperator.html`

#### public static boolean
**parseBoolean**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s)

Parses the string argument as a boolean. The `boolean`
returned represents the value `true` if the string argument
is not `null` and is equal, ignoring case, to the string
`"true"`.


Example: `Boolean.parseBoolean("True")` returns `true`.  

Example: `Boolean.parseBoolean("yes")` returns `false`.

##### Parameters

| s | the `String` containing the boolean representation to be parsed |
|---|---|

##### Returns

- the boolean represented by the string argument

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Returns a `String` object representing this Boolean's
value. If this object represents the value `true`,
a string equal to `"true"` is returned. Otherwise, a
string equal to `"false"` is returned.

##### Returns

- a string representation of this object.

#### public static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
(boolean b)

Returns a `String` object representing the specified
boolean. If the specified boolean is `true`, then
the string `"true"` will be returned, otherwise the
string `"false"` will be returned.

##### Parameters

| b | the boolean to be converted |
|---|---|

##### Returns

- the string representation of the specified `boolean`

#### public static [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html)
**valueOf**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s)

Returns a `Boolean` with a value represented by the
specified string. The `Boolean` returned represents a
true value if the string argument is not `null`
and is equal, ignoring case, to the string `"true"`.

##### Parameters

| s | a string. |
|---|---|

##### Returns

- the `Boolean` value represented by the string.

#### public static [Boolean](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html)
**valueOf**
(boolean b)

Returns a `Boolean` instance representing the specified
`boolean` value. If the specified `boolean` value
is `true`, this method returns `Boolean.TRUE`;
if it is `false`, this method returns `Boolean.FALSE`.
If a new `Boolean` instance is not required, this method
should generally be used in preference to the constructor
`https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Boolean.html#Boolean(boolean)`, as this method is likely to yield
significantly better space and time performance.

##### Parameters

| b | a boolean value. |
|---|---|

##### Returns

- a `Boolean` instance representing `b`.