Java Collection Contain contains(Collection coll, Object o, Comparator c)

Here you can find the source of contains(Collection coll, Object o, Comparator c)

Description

Answer whether or not coll contains Object o, but not based on equal(), but on compareTo()==0

License

Open Source License

Parameter

Parameter Description
coll a parameter
o a parameter
c a parameter

Declaration

public static boolean contains(Collection coll, Object o, Comparator c) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from  w w  w.j a v  a2s . co  m
     * Answer whether or not coll contains Object o, 
     * but not based on equal(), but on compareTo()==0
     * @param coll
     * @param o
     * @param c
     * @return
     */
    public static boolean contains(Collection coll, Object o, Comparator c) {
        boolean answer = false;
        for (Iterator i = coll.iterator(); i.hasNext() && !answer;) {
            answer = 0 == c.compare(o, i.next());
        }
        return answer;
    }
}

Related

  1. contains( C collection, K key)
  2. contains(Collection c, Object o, Comparator comparator)
  3. contains(Collection collection, Object object)
  4. contains(Collection objects, Object o)
  5. contains(Collection searchIn, Object[] find)
  6. contains(Collection stringCollection, String value)