Below is sample code.
How to remove a specific element in ArrayList?
import java.util.ArrayList;
class A {
int value;
public A(int newValue) {
setValue(newValue);
}
public int getValue() {
return value;
}
public void setValue(int newValue) {
value = newValue;
}
}
class B {
ArrayList <A> valuesOfA = new ArrayList<>();
valuesOfA.add(new A(5));
System.out.println("Adding...");
for (A value: valueOfA) {
System.out.println(value); //prints the values added.
}
valuesOfA.remove(new A(5));
System.out.println("Removed");
for (A value: valueOfA) {
System.out.println(value);
}
}
Element as still not been removed. What is the solution for this?