So I have the following relevant code:
public static TreeSet<Object> set;
public static void remove(Object object){
for (Object o : set){
if (o.equals(object)){
System.out.println("removing " + o);
set.remove(o);
}
}
}
I add a few objects to that TreeSet, then I call remove with a certain object1 as an argument. The object1 is in the set, as
removingobject1
is printed out.
Yet, when I then print out the whole set after that using a for-loop like this:
for (Object o: set){
System.out.println(o);
}
It still prints out the whole set including object1. It was clearly in the collection before, which Java was able to recognize, yet calling set.remove(o) results in absolutely nothing.
edit: I tried to keep the question as general as possible, but here are the objects that I'm using:
public class Player implements Comparable<Player>{
public String firstname;
public String lastname;
public int value;
public Position position;
public Player(String firstname, String lastname, int value, Position position){
this.firstname = firstname;
this.lastname = lastname;
this.value = value;
this.position = position;
}
public String toString(){
return(firstname + " " + lastname")
}
public int compareTo(Player player){
if (this.value > player.value){
return -1;
} else {
return 1;
}
}