Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/java/lang/Boolean#lfields) \| [Ctors](https://developer.android.com/reference/java/lang/Boolean#pubctors) \| [Methods](https://developer.android.com/reference/java/lang/Boolean#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/lang/Boolean#inhmethods)

# Boolean

` public final class Boolean `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/lang/Comparable<https://developer.android.com/reference/java/lang/Boolean>, https://developer.android.com/reference/java/io/Serializable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.lang.Boolean |

<br />

*** ** * ** ***

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`.

This is a [value-based](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/doc-files/ValueBased.html) class; programmers should treat instances that are [equal](https://developer.android.com/reference/java/lang/Boolean#equals(java.lang.Object)) as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.

## Summary

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/java/lang/Boolean` | `https://developer.android.com/reference/java/lang/Boolean#FALSE` The `Boolean` object corresponding to the primitive value `false`. |
| ` public static final https://developer.android.com/reference/java/lang/Boolean` | `https://developer.android.com/reference/java/lang/Boolean#TRUE` The `Boolean` object corresponding to the primitive value `true`. |
| ` public static final https://developer.android.com/reference/java/lang/Class<https://developer.android.com/reference/java/lang/Boolean>` | `https://developer.android.com/reference/java/lang/Boolean#TYPE` The Class object representing the primitive type boolean. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Boolean#Boolean(boolean)(boolean value) ` *This constructor is deprecated. It is rarely appropriate to use this constructor. The static factory `https://developer.android.com/reference/java/lang/Boolean#valueOf(boolean)` is generally a better choice, as it is likely to yield significantly better space and time performance. Also consider using the final fields `https://developer.android.com/reference/java/lang/Boolean#TRUE` and `https://developer.android.com/reference/java/lang/Boolean#FALSE` if possible.* |
| ` https://developer.android.com/reference/java/lang/Boolean#Boolean(java.lang.String)(https://developer.android.com/reference/java/lang/String s) ` *This constructor is deprecated. It is rarely appropriate to use this constructor. Use `https://developer.android.com/reference/java/lang/Boolean#parseBoolean(java.lang.String)` to convert a string to a `boolean` primitive, or use `https://developer.android.com/reference/java/lang/Boolean#valueOf(java.lang.String)` to convert a string to a `Boolean` object.* |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/java/lang/Boolean#booleanValue()() ` Returns the value of this `Boolean` object as a boolean primitive. |
| ` static int` | ` https://developer.android.com/reference/java/lang/Boolean#compare(boolean,%20boolean)(boolean x, boolean y) ` Compares two `boolean` values. |
| ` int` | ` https://developer.android.com/reference/java/lang/Boolean#compareTo(java.lang.Boolean)(https://developer.android.com/reference/java/lang/Boolean b) ` Compares this `Boolean` instance with another. |
| ` boolean` | ` https://developer.android.com/reference/java/lang/Boolean#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object 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` | ` https://developer.android.com/reference/java/lang/Boolean#getBoolean(java.lang.String)(https://developer.android.com/reference/java/lang/String name) ` Returns `true` if and only if the system property named by the argument exists and is equal to, ignoring case, the string `"true"`. |
| ` int` | ` https://developer.android.com/reference/java/lang/Boolean#hashCode()() ` Returns a hash code for this `Boolean` object. |
| ` static int` | ` https://developer.android.com/reference/java/lang/Boolean#hashCode(boolean)(boolean value) ` Returns a hash code for a `boolean` value; compatible with `Boolean.hashCode()`. |
| ` static boolean` | ` https://developer.android.com/reference/java/lang/Boolean#logicalAnd(boolean,%20boolean)(boolean a, boolean b) ` Returns the result of applying the logical AND operator to the specified `boolean` operands. |
| ` static boolean` | ` https://developer.android.com/reference/java/lang/Boolean#logicalOr(boolean,%20boolean)(boolean a, boolean b) ` Returns the result of applying the logical OR operator to the specified `boolean` operands. |
| ` static boolean` | ` https://developer.android.com/reference/java/lang/Boolean#logicalXor(boolean,%20boolean)(boolean a, boolean b) ` Returns the result of applying the logical XOR operator to the specified `boolean` operands. |
| ` static boolean` | ` https://developer.android.com/reference/java/lang/Boolean#parseBoolean(java.lang.String)(https://developer.android.com/reference/java/lang/String s) ` Parses the string argument as a boolean. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Boolean#toString()() ` Returns a `String` object representing this Boolean's value. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Boolean#toString(boolean)(boolean b) ` Returns a `String` object representing the specified boolean. |
| ` static https://developer.android.com/reference/java/lang/Boolean` | ` https://developer.android.com/reference/java/lang/Boolean#valueOf(java.lang.String)(https://developer.android.com/reference/java/lang/String s) ` Returns a `Boolean` with a value represented by the specified string. |
| ` static https://developer.android.com/reference/java/lang/Boolean` | ` https://developer.android.com/reference/java/lang/Boolean#valueOf(boolean)(boolean b) ` Returns a `Boolean` instance representing the specified `boolean` value. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/java/lang/Comparable ` ` abstract int` ` https://developer.android.com/reference/java/lang/Comparable#compareTo(T)(https://developer.android.com/reference/java/lang/Boolean o) `

Compares this object with the specified object for order.

## Fields

### FALSE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Boolean FALSE
```

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

<br />

### TRUE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Boolean TRUE
```

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

<br />

### TYPE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Class<Boolean> TYPE
```

The Class object representing the primitive type boolean.

<br />

## Public constructors

### Boolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Boolean (boolean value)
```

<br />

**This constructor is deprecated.**   

It is rarely appropriate to use this constructor. The static factory `https://developer.android.com/reference/java/lang/Boolean#valueOf(boolean)` is generally a better choice, as it is likely to yield significantly better space and time performance. Also consider using the final fields `https://developer.android.com/reference/java/lang/Boolean#TRUE` and `https://developer.android.com/reference/java/lang/Boolean#FALSE` if possible.

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

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: the value of the `Boolean`. <br /> |

### Boolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Boolean (String s)
```

<br />

**This constructor is deprecated.**   

It is rarely appropriate to use this constructor. Use `https://developer.android.com/reference/java/lang/Boolean#parseBoolean(java.lang.String)` to convert a string to a `boolean` primitive, or use `https://developer.android.com/reference/java/lang/Boolean#valueOf(java.lang.String)` to convert a string to a `Boolean` object.

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, allocates a `Boolean` object representing the value `false`.

<br />

| Parameters ||
|---|---|
| `s` | `String`: the string to be converted to a `Boolean`. <br /> |

## Public methods

### booleanValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean booleanValue ()
```

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

<br />

| Returns ||
|---|---|
| `boolean` | the primitive `boolean` value of this object. <br /> |

### compare

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 />

<br />

| Parameters ||
|---|---|
| `x` | `boolean`: the first `boolean` to compare <br /> |
| `y` | `boolean`: the second `boolean` to compare <br /> |

| Returns ||
|---|---|
| `int` | the value `0` if `x == y`; a value less than `0` if `!x && y`; and a value greater than `0` if `x && !y` <br /> |

### compareTo

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int compareTo (Boolean b)
```

Compares this `Boolean` instance with another.

<br />

| Parameters ||
|---|---|
| `b` | `Boolean`: the `Boolean` instance to be compared <br /> |

| Returns ||
|---|---|
| `int` | 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 <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the argument is `null` |

**See also:**

- `https://developer.android.com/reference/java/lang/Comparable`

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object 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.

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: the object to compare with. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the Boolean objects represent the same value; `false` otherwise. <br /> |

### getBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean getBoolean (String name)
```

Returns `true` if and only if the system property named by the argument exists and is equal to, ignoring case, the string `"true"`. 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.

<br />

| Parameters ||
|---|---|
| `name` | `String`: the system property name. <br /> |

| Returns ||
|---|---|
| `boolean` | the `boolean` value of the system property. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | for the same reasons as `https://developer.android.com/reference/java/lang/System#getProperty(java.lang.String)` |

**See also:**

- `https://developer.android.com/reference/java/lang/System#getProperty(java.lang.String)`
- `https://developer.android.com/reference/java/lang/System#getProperty(java.lang.String,%20java.lang.String)`

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code for this `Boolean` object.

<br />

| Returns ||
|---|---|
| `int` | the integer `1231` if this object represents `true`; returns the integer `1237` if this object represents `false`. <br /> |

### hashCode

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int hashCode (boolean value)
```

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

<br />

| Parameters ||
|---|---|
| `value` | `boolean`: the value to hash <br /> |

| Returns ||
|---|---|
| `int` | a hash code value for a `boolean` value. <br /> |

### logicalAnd

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean logicalAnd (boolean a, 
                boolean b)
```

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

<br />

| Parameters ||
|---|---|
| `a` | `boolean`: the first operand <br /> |
| `b` | `boolean`: the second operand <br /> |

| Returns ||
|---|---|
| `boolean` | the logical AND of `a` and `b` <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/function/BinaryOperator`

### logicalOr

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean logicalOr (boolean a, 
                boolean b)
```

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

<br />

| Parameters ||
|---|---|
| `a` | `boolean`: the first operand <br /> |
| `b` | `boolean`: the second operand <br /> |

| Returns ||
|---|---|
| `boolean` | the logical OR of `a` and `b` <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/function/BinaryOperator`

### logicalXor

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean logicalXor (boolean a, 
                boolean b)
```

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

<br />

| Parameters ||
|---|---|
| `a` | `boolean`: the first operand <br /> |
| `b` | `boolean`: the second operand <br /> |

| Returns ||
|---|---|
| `boolean` | the logical XOR of `a` and `b` <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/function/BinaryOperator`

### parseBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean parseBoolean (String 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"`. Otherwise, a false value is returned, including for a null argument.

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

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

<br />

| Parameters ||
|---|---|
| `s` | `String`: the `String` containing the boolean representation to be parsed <br /> |

| Returns ||
|---|---|
| `boolean` | the boolean represented by the string argument <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String 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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of this object. <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String 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.

<br />

| Parameters ||
|---|---|
| `b` | `boolean`: the boolean to be converted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the string representation of the specified `boolean` <br /> |

### valueOf

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Boolean valueOf (String 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"`. Otherwise, a false value is returned, including for a null argument.

<br />

| Parameters ||
|---|---|
| `s` | `String`: a string. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Boolean` | the `Boolean` value represented by the string. <br /> |

### valueOf

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Boolean 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://developer.android.com/reference/java/lang/Boolean#Boolean(boolean)`, as this method is likely to yield significantly better space and time performance.

<br />

| Parameters ||
|---|---|
| `b` | `boolean`: a boolean value. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Boolean` | a `Boolean` instance representing `b`. <br /> |