I have an ArrayList
For Example
class Car{
String carName;
int carType;
}
Now, I have to find if the
If you have
class Car{
String carName;
int carType;
}
and
List list;
that contains a list of cars, then you could have a method like
public static boolean hasDuplicates(List p_cars) {
final List usedNames = new ArrayList();
for (Car car : p_cars) {
final String name = car.carName;
if (usedNames.contains(name)) {
return true;
}
usedNames.add(name);
}
return false;
}
to find out whether the list of cars have cars with duplicate names.