# Predicate

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

# Predicate

`
public


interface
Predicate
`  
`


`

|-----------------------------------|
| java.util.function.Predicate\<T\> |

<br />

*** ** * ** ***

Represents a predicate (boolean-valued function) of one argument.

This is a[functional interface](https://developer.android.com/reference/java/util/function/package-summary)whose functional method is[test(java.lang.Object)](https://developer.android.com/reference/java/util/function/Predicate#test(T)).

## Summary

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

## Public methods

### and

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

```
public Predicate<T> and (Predicate<? super 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.

<br />

|                                        Parameters                                         ||
|---------|----------------------------------------------------------------------------------|
| `other` | `Predicate`: a predicate that will be logically-ANDed with this predicate <br /> |

|                                                                                                    Returns                                                                                                     ||
|----------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<T>` | a composed predicate that represents the short-circuiting logical AND of this predicate and the`other`predicate <br /> |

|                                                      Throws                                                      ||
|------------------------------------------------------------------------------------------------|------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if other is null |

### isEqual

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

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

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

<br />

|                                                Parameters                                                 ||
|-------------|----------------------------------------------------------------------------------------------|
| `targetRef` | `Object`: the object reference with which to compare for equality, which may be`null` <br /> |

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

### negate

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

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

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

<br />

|                                                                              Returns                                                                              ||
|----------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<T>` | a predicate that represents the logical negation of this predicate <br /> |

### not

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

```
public static Predicate<T> not (Predicate<? super T> target)
```

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

<br />

|                    Parameters                     ||
|----------|-----------------------------------------|
| `target` | `Predicate`: predicate to negate <br /> |

|                                                                            Returns                                                                            ||
|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<T>` | a predicate that negates the results of the supplied predicate <br /> |

|                                                      Throws                                                       ||
|------------------------------------------------------------------------------------------------|-------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if target is null |

### or

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

```
public Predicate<T> or (Predicate<? super 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.

<br />

|                                        Parameters                                        ||
|---------|---------------------------------------------------------------------------------|
| `other` | `Predicate`: a predicate that will be logically-ORed with this predicate <br /> |

|                                                                                                    Returns                                                                                                    ||
|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<T>` | a composed predicate that represents the short-circuiting logical OR of this predicate and the`other`predicate <br /> |

|                                                      Throws                                                      ||
|------------------------------------------------------------------------------------------------|------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if other is null |

### test

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

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

Evaluates this predicate on the given argument.

<br />

|             Parameters              ||
|-----|--------------------------------|
| `t` | `T`: the input argument <br /> |

|                                        Returns                                        ||
|-----------|----------------------------------------------------------------------------|
| `boolean` | `true`if the input argument matches the predicate, otherwise`false` <br /> |