0
Public boolean remove(Grocery ent)
I have an arraylist Arraylist <Grocery> = shoppingList; How would I search in the shoppingList, if found ent in the list remove it, set value to found How would i do this in this method Public boolean remove(Grocery ent) { Boolean found = true; Return found; }
3 Answers
0
try if/else like if âentâ contains in shoppingList then set found true
and if found is true Remove ent
u can also add a boolean deleted so after u deleted ent u can set deleted true and returned then
0
can someone show a sample code of how i should do it?
0
ArrayList<Grocery> g=new ArraryList<>();
g.add(ent);
g.add(ent2); //for adding to List
public boolean remove(Grocery ent)
{
If( g.contains(ent) )
{
g.remove(ent); //for removing
return true;
}
else
return false;
//A sample only, not complete ....