Check to see if the given index is with in the range of collection items - Android java.util

Android examples for java.util:Collection Find

Description

Check to see if the given index is with in the range of collection items

Demo Code


//package com.java2s;

import java.util.Collection;

public class Main {
    /**/* w  w  w  .j  av  a  2  s .c o m*/
     * Check to see if the given index is with in the range of collection items
     *
     * @return true if the index is a index in the list, false otherwise
     */
    public static boolean isValidIndex(Collection collection, int index) {
        return !isEmpty(collection) && index < collection.size()
                && index >= 0;
    }

    /**
     * Is this list empty. Checks for null as well as size.
     *
     * @return true if empty, false if not
     */
    public static boolean isEmpty(Collection collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * Is this list empty. Checks for null as well as size.
     *
     * @return true if empty, false if not
     */
    public static boolean isEmpty(Object[] collection) {
        return collection == null || collection.length == 0;
    }
}

Related Tutorials