I'm trying to find an element in the ArrayList "minions" with the highest "evilLevel" (that's defined in another class).
public Minion(String name, int evilLevel, boolean onMission) - from class Minion
private Set<Minion> minions;
int maxEvilLevel = 0;
Minion theMostEvilMinion;
public MinionRegister(){
minions = new HashSet<Minion>();
}
public Minion getMostEvilMinion(){
if(minions.isEmpty()){
return null;
}
for(Minion m : minions){
if(m.getEvilLevel() > maxEvilLevel) {
maxEvilLevel = m.getEvilLevel();
Minion theMostEvilMinion = m;
}
}
return theMostEvilMinion;
}
Unfortunately the method returns "null"
ArrayList, but your code is using aHashSet. They are not the same thing.