So I have a Java files named ConeList
and ConeListMenuApp
. In ConeListMenuApp
I have a switch method that allows the user to read in a file that populates an ArrayList
with Cone
objects. One of the other options is to delete a cone. The user is prompted to enter a label (name of the cone) and then the deleteCone
method from my ConeList
is called. For some reason, I keep getting an issue where that cone is not being found in the ArrayList
. It returns ""Label Entered" not found." Which would make sense except its there as my methods for printing and finding it both show it. Here is my code for the deleteCone
method.
public Cone deleteCone(String labelIn) {
int index = -1;
Cone c = null;
for (Cone d : conesList) {
if (d.getLabel() == labelIn) {
index = conesList.indexOf(d);
break;
}
}
if (index >= 0) {
c = conesList.remove(index);
}
return c;
If anyone could help me out with understanding where my issue may lie I would greatly appreciate it. I am fairly new to java and sort of stuck trying to figure out why I'm not able to remove the object.