# Predicate

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/util/Predicate "View this page in Java")

<br />

```
interface Predicate<T>
```

<br />

*** ** * ** ***

Compat version of[java.util.function.Predicate](https://developer.android.com/reference/java/util/function/Predicate.html)  

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

## Summary

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

## Public functions

### and

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

```
fun and(other: Predicate<T!>!): Predicate<T!>!
```

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                                                |
|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| `other: `[Predicate](https://developer.android.com/reference/kotlin/androidx/core/util/Predicate)`<T!>!` | a predicate that will be logically-ANDed with this predicate |

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

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|------------------|
| [java.lang.NullPointerException](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)  

```
java-static fun <T> isEqual(targetRef: Any!): Predicate<T!>!
```

Returns a predicate that tests if two arguments are equal according to[equals](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                                      |
| `targetRef: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!` | the object reference with which to compare for equality, which may be`null` |

|                                             Returns                                             |
|-------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/kotlin/androidx/core/util/Predicate)`<T!>!` | a predicate that tests if two arguments are equal according to[equals](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)  

```
fun negate(): Predicate<T!>!
```

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

|                                             Returns                                             |
|-------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [Predicate](https://developer.android.com/reference/kotlin/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)  

```
java-static fun <T> not(target: Predicate<T!>!): Predicate<T!>!
```

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 |
| `target: `[Predicate](https://developer.android.com/reference/kotlin/androidx/core/util/Predicate)`<T!>!` | predicate to negate                              |

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

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|-------------------|
| [java.lang.NullPointerException](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)  

```
fun or(other: Predicate<T!>!): Predicate<T!>!
```

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                                                |
|----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| `other: `[Predicate](https://developer.android.com/reference/kotlin/androidx/core/util/Predicate)`<T!>!` | a predicate that will be logically-ORed with this predicate |

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

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|------------------|
| [java.lang.NullPointerException](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)  

```
fun test(t: T!): Boolean
```

Evaluates this predicate on the given argument.  

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

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if the input argument matches the predicate, otherwise`false` |