# Predicate

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/util/Predicate.java+class:androidx.core.util.Predicate) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

*** ** * ** ***


```
public interface Predicate<T>
```

<br />

*** ** * ** ***

Compat version of `https://developer.android.com/reference/java/util/function/Predicate.html`

| Parameters |
|---|---|
| `<T>` | the type of the input to the operation |

## Summary

| ### Public methods |
|---|---|
| `default https://developer.android.com/reference/androidx/core/util/Predicate<T>` | `https://developer.android.com/reference/androidx/core/util/Predicate#and(androidx.core.util.Predicate<? super T>)(https://developer.android.com/reference/androidx/core/util/Predicate<T> other)` Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. |
| `default static https://developer.android.com/reference/androidx/core/util/Predicate<T>` | `<T> https://developer.android.com/reference/androidx/core/util/Predicate#isEqual(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html targetRef)` Returns a predicate that tests if two arguments are equal according to `https://developer.android.com/reference/java/util/Objects.html#equals(java.lang.Object, java.lang.Object)`. |
| `default https://developer.android.com/reference/androidx/core/util/Predicate<T>` | `https://developer.android.com/reference/androidx/core/util/Predicate#negate()()` Returns a predicate that represents the logical negation of this predicate. |
| `default static https://developer.android.com/reference/androidx/core/util/Predicate<T>` | `<T> https://developer.android.com/reference/androidx/core/util/Predicate#not(androidx.core.util.Predicate<? super T>)(https://developer.android.com/reference/androidx/core/util/Predicate<T> target)` Returns a predicate that is the negation of the supplied predicate. |
| `default https://developer.android.com/reference/androidx/core/util/Predicate<T>` | `https://developer.android.com/reference/androidx/core/util/Predicate#or(androidx.core.util.Predicate<? super T>)(https://developer.android.com/reference/androidx/core/util/Predicate<T> other)` Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/util/Predicate#test(T)(T t)` Evaluates this predicate on the given argument. |

## Public methods

### and

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
default Predicate<T> and(Predicate<T> other)
```

Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. When evaluating the composed predicate, if this predicate is `false`, then the `other` predicate is not evaluated.

Any exceptions thrown during evaluation of either predicate are relayed to the caller; if evaluation of this predicate throws an exception, the `other` predicate will not be evaluated.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T> other` | a predicate that will be logically-ANDed with this predicate |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T>` | a composed predicate that represents the short-circuiting logical AND of this predicate and the `other` predicate |

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

### isEqual

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
default static Predicate<T> <T> isEqual(Object targetRef)
```

Returns a predicate that tests if two arguments are equal according to `https://developer.android.com/reference/java/util/Objects.html#equals(java.lang.Object, java.lang.Object)`.

| Parameters |
|---|---|
| `<T>` | the type of arguments to the predicate |
| `https://developer.android.com/reference/java/lang/Object.html targetRef` | the object reference with which to compare for equality, which may be `null` |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T>` | a predicate that tests if two arguments are equal according to `https://developer.android.com/reference/java/util/Objects.html#equals(java.lang.Object, java.lang.Object)` |

### negate

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
default Predicate<T> negate()
```

Returns a predicate that represents the logical negation of this predicate.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T>` | a predicate that represents the logical negation of this predicate |

### not

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
default static Predicate<T> <T> not(Predicate<T> target)
```

Returns a predicate that is the negation of the supplied predicate. This is accomplished by returning result of the calling `target.negate()`.

| Parameters |
|---|---|
| `<T>` | the type of arguments to the specified predicate |
| `https://developer.android.com/reference/androidx/core/util/Predicate<T> target` | predicate to negate |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T>` | a predicate that negates the results of the supplied predicate |

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

### or

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
default Predicate<T> or(Predicate<T> other)
```

Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. When evaluating the composed predicate, if this predicate is `true`, then the `other` predicate is not evaluated.

Any exceptions thrown during evaluation of either predicate are relayed to the caller; if evaluation of this predicate throws an exception, the `other` predicate will not be evaluated.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T> other` | a predicate that will be logically-ORed with this predicate |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/util/Predicate<T>` | a composed predicate that represents the short-circuiting logical OR of this predicate and the `other` predicate |

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

### test

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/core#1.2.0)

```
abstract boolean test(T t)
```

Evaluates this predicate on the given argument.

| Parameters |
|---|---|
| `T t` | the input argument |

| Returns |
|---|---|
| `boolean` | `true` if the input argument matches the predicate, otherwise `false` |