# CursorJoiner

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

# CursorJoiner

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/database/CursorJoiner "View this page in Kotlin")\|Java

`
public

final

class
CursorJoiner
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Iterable](https://developer.android.com/reference/java/lang/Iterable)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>,

`[Iterator](https://developer.android.com/reference/java/util/Iterator)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>


`

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

<br />

*** ** * ** ***

Does a join on two cursors using the specified columns. The cursors must already be sorted on each of the specified columns in ascending order. This joiner only supports the case where the tuple of key column values is unique.

Typical usage:  

```
 CursorJoiner joiner = new CursorJoiner(cursorA, keyColumnsofA, cursorB, keyColumnsofB);
 for (CursorJoiner.Result joinerResult : joiner) {
     switch (joinerResult) {
         case LEFT:
             // handle case where a row in cursorA is unique
             break;
         case RIGHT:
             // handle case where a row in cursorB is unique
             break;
         case BOTH:
             // handle case where a row with the same key is in both cursors
             break;
     }
 }
 
```

<br />

## Summary

|                                                                                                                                                                                                                                                                                                               ### Public constructors                                                                                                                                                                                                                                                                                                               ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[CursorJoiner](https://developer.android.com/reference/android/database/CursorJoiner#CursorJoiner(android.database.Cursor,%20java.lang.String[],%20android.database.Cursor,%20java.lang.String[]))`(`[Cursor](https://developer.android.com/reference/android/database/Cursor)` cursorLeft, `[String[]](https://developer.android.com/reference/java/lang/String)` columnNamesLeft, `[Cursor](https://developer.android.com/reference/android/database/Cursor)` cursorRight, `[String[]](https://developer.android.com/reference/java/lang/String)` columnNamesRight) ` Initializes the CursorJoiner and resets the cursors to the first row. |

|                                                                                                                                                                                      ### Public methods                                                                                                                                                                                      ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                                                                                                                         | ` `[hasNext](https://developer.android.com/reference/android/database/CursorJoiner#hasNext())`() ` Returns whether or not there are more rows to compare using next().                                   |
| ` `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>` | ` `[iterator](https://developer.android.com/reference/android/database/CursorJoiner#iterator())`() ` Returns an iterator over elements of type`T`.                                                       |
| ` `[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)                                                                             | ` `[next](https://developer.android.com/reference/android/database/CursorJoiner#next())`() ` Returns the comparison result of the next row from each cursor.                                             |
| ` void`                                                                                                                                                                            | ` `[remove](https://developer.android.com/reference/android/database/CursorJoiner#remove())`() ` Removes from the underlying collection the last element returned by this iterator (optional operation). |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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` `[java.lang.Iterable](https://developer.android.com/reference/java/lang/Iterable)` ` |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default void`                                                                                                                                                                                  | ` `[forEach](https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer<?%20super%20T>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super T> action) ` Performs the given action for each element of the`Iterable`until all elements have been processed or the action throws an exception. | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>`      | ` `[iterator](https://developer.android.com/reference/java/lang/Iterable#iterator())`() ` Returns an iterator over elements of type`T`.                                                                                                                                                                                                                                   | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>` | ` `[spliterator](https://developer.android.com/reference/java/lang/Iterable#spliterator())`() ` Creates a[Spliterator](https://developer.android.com/reference/java/util/Spliterator)over the elements described by this`Iterable`.                                                                                                                                       | ||
| From interface` `[java.util.Iterator](https://developer.android.com/reference/java/util/Iterator)` ` |-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default void`                                                                                                 | ` `[forEachRemaining](https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super E> action) ` Performs the given action for each remaining element until all elements have been processed or the action throws an exception. | | ` abstract boolean`                                                                                             | ` `[hasNext](https://developer.android.com/reference/java/util/Iterator#hasNext())`() ` Returns`true`if the iteration has more elements.                                                                                                                                                                                                                                              | | ` abstract `[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result) | ` `[next](https://developer.android.com/reference/java/util/Iterator#next())`() ` Returns the next element in the iteration.                                                                                                                                                                                                                                                          | | ` default void`                                                                                                 | ` `[remove](https://developer.android.com/reference/java/util/Iterator#remove())`() ` Removes from the underlying collection the last element returned by this iterator (optional operation).                                                                                                                                                                                         | ||

## Public constructors

### CursorJoiner

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

```
public CursorJoiner (Cursor cursorLeft, 
                String[] columnNamesLeft, 
                Cursor cursorRight, 
                String[] columnNamesRight)
```

Initializes the CursorJoiner and resets the cursors to the first row. The left and right column name arrays must have the same number of columns.

<br />

|                                       Parameters                                       ||
|--------------------|--------------------------------------------------------------------|
| `cursorLeft`       | `Cursor`: The left cursor to compare <br />                        |
| `columnNamesLeft`  | `String`: The column names to compare from the left cursor <br />  |
| `cursorRight`      | `Cursor`: The right cursor to compare <br />                       |
| `columnNamesRight` | `String`: The column names to compare from the right cursor <br /> |

## Public methods

### hasNext

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

```
public boolean hasNext ()
```

Returns whether or not there are more rows to compare using next().

<br />

|                         Returns                          ||
|-----------|-----------------------------------------------|
| `boolean` | true if there are more rows to compare <br /> |

### iterator

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

```
public Iterator<CursorJoiner.Result> iterator ()
```

Returns an iterator over elements of type`T`.

<br />

|                                                                                               Returns                                                                                                ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|
| [Iterator](https://developer.android.com/reference/java/util/Iterator)`<`[CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result)`>` | an Iterator. <br /> |

### next

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

```
public CursorJoiner.Result next ()
```

Returns the comparison result of the next row from each cursor. If one cursor has no more rows but the other does then subsequent calls to this will indicate that the remaining rows are unique.

The caller must check that hasNext() returns true before calling this.

Once next() has been called the cursors specified in the result of the call to next() are guaranteed to point to the row that was indicated. Reading values from the cursor that was not indicated in the call to next() will result in undefined behavior.

<br />

|                                                                                                                                     Returns                                                                                                                                     ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CursorJoiner.Result](https://developer.android.com/reference/android/database/CursorJoiner.Result) | LEFT, if the row pointed to by the left cursor is unique, RIGHT if the row pointed to by the right cursor is unique, BOTH if the rows in both cursors are the same. <br /> |

### remove

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

```
public void remove ()
```

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to[next()](https://developer.android.com/reference/java/util/Iterator#next()).

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the[forEachRemaining](https://developer.android.com/reference/java/util/Iterator#forEachRemaining(java.util.function.Consumer<?%20super%20E>))method.

<br />