java check if string appears twice in arraylist

Solutions on MaxInterview for java check if string appears twice in arraylist by the best coders in the world

showing results for - "java check if string appears twice in arraylist"
Florencia
24 Jul 2016
1//same as the Grepper awnser but for anything
2//gets the amount of times the object appears in the array
3public static int amountOfTimesObjectAppearsInArray(ArrayList<?> array, Object checkMe) {
4    int numCount = 0;
5    for (Object o : array) {
6        if (o.equals(checkMe)) numCount++;
7    }
8    return numCount;
9}
10//check if it appears more than once
11public static boolean objectAppearsInArrayMoreThanOnce(ArrayList<?> array, Object checkMe) {
12    return amountOfTimesObjectAppearsInArray(array, checkMe)>1;
13}