Public boolean remove(Grocery ent) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

9th Sep 2019, 11:04 PM
Vanessa Liaw
Vanessa Liaw - avatar
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
10th Sep 2019, 2:08 AM
Mumtaz Colkusu
Mumtaz Colkusu - avatar
0
can someone show a sample code of how i should do it?
10th Sep 2019, 2:18 AM
Vanessa Liaw
Vanessa Liaw - avatar
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 ....
22nd Nov 2019, 4:04 PM
Jayakrishna 🇮🇳