Add each item of this android.database.Cursor to the collection parameter. - Android Database

Android examples for Database:Cursor

Description

Add each item of this android.database.Cursor to the collection parameter.

Demo Code


import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;

public class Main{
    /**//w ww.j  ava  2  s.c o m
     * Add each item of this {@link android.database.Cursor} to the {@code collection} parameter.
     * Closes the cursor once completed.
     *
     * @return the same collection as the parameter.
     * @see #consumeToArrayList(com.venmo.cursor.IterableCursor)
     * @see #consumeToLinkedList(com.venmo.cursor.IterableCursor)
     * @see #consumeToLinkedHashSet(com.venmo.cursor.IterableCursor)
     */
    public static <T, C extends Collection<T>> C consumeToCollection(
            IterableCursor<T> cursor, C collection) {
        try {
            for (T t : cursor) {
                collection.add(t);
            }
        } finally {
            cursor.close();
        }
        return collection;
    }
}

Related Tutorials