I have an ArrayList
For Example
class Car{
String carName;
int carType;
}
Now, I have to find if the
Try this:
List cars = getCars();
Set names = new HashSet();
for (Car car:cars) {
if (names.contains(car.getName()) {
duplicate(car); // some magic handler
} else {
names.add(car.getName());
}
}
Note: this will give you the car names that are duplicate. A follow on would be extracting all cars with those names from the list (if you need the Car objects)