📜  java检查字符串是否在arraylist中出现两次 - Java代码示例

📅  最后修改于: 2022-03-11 14:52:21.288000             🧑  作者: Mango

代码示例1
//same as the Grepper awnser but for anything
//gets the amount of times the object appears in the array
public static int amountOfTimesObjectAppearsInArray(ArrayList array, Object checkMe) {
    int numCount = 0;
    for (Object o : array) {
        if (o.equals(checkMe)) numCount++;
    }
    return numCount;
}
//check if it appears more than once
public static boolean objectAppearsInArrayMoreThanOnce(ArrayList array, Object checkMe) {
    return amountOfTimesObjectAppearsInArray(array, checkMe)>1;
}