Here you can find the source of contains(Collection c, Object o, Comparator comparator)
Parameter | Description |
---|---|
comparator | if not null, used to determine if two items are the same |
public static boolean contains(Collection c, Object o, Comparator comparator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//w ww .j a v a 2 s. c om * checks whether the object o is contained in the collection c * * @param comparator if not null, used to determine if two items are the same */ public static boolean contains(Collection c, Object o, Comparator comparator) { if (comparator == null) { // simply check if 'c' contains the pointer 'o' return c.contains(o); } else { // look into 'c' for occurence of 'o' for (Object o2 : c) { if (comparator.compare(o, o2) == 0) { // the objects match return true; } } } return false; } }