Check if an Integer is Contained in List by binary search - Java java.util

Java examples for java.util:List Contain

Description

Check if an Integer is Contained in List by binary search

Demo Code


//package com.book2s;
import java.util.*;

public class Main {


    public static boolean isContain(List<Integer> list, Integer i) {
        if (isCollectionEmpty(list) || i == null) {
            return false;
        }//w  w w  . j  av a 2s . c  om
        return Collections.binarySearch(list, i) >= 0;
    }

    public static <T> boolean isCollectionEmpty(Collection<T> collection) {
        return collection == null || collection.isEmpty();
    }
}

Related Tutorials