java - Find an a specific instance, what is the best approach -
so imagine have 2 instances of class: public class myclass { public void sayhello() { system.out.println("hello"); } } = new myclass(); b = new myclass(); now add object, such as: public class otherclass { private arraylist<myclass> myclslist = new arraylist<>(); public void add(myclass obj) { myclslist.add(obj); } public void remove(myclass obj) { // ???? } } c = new otherclass(); c.add(a); c.add(b); now want remove 1 specific instance e.g c.remove(a); could iterate on them , test equality, mean should theoretically work, since 2 instances have distinct "internal pointers"? i guess using hashmap based approach more efficient, can use key there (suppose can't add unique instance ids or something). edit: there confusion i'd know. key here i'd know if there way of removing specific instance c's arraylist or whatever aggregator object might use, providing respecti...