removing all false elements from a linked list in java

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



removing all false elements from a linked list in java



I have a linked list of fish data shown here


//create linked list of fish data called fl
LinkedList<FishData> fl = new LinkedList<FishData>();
//Here are a few data items
fl.add(new FishData("American Eel ", 9, "Summer/Spring ", 25 , false));
fl.add(new FishData("Hammerhead Shark ", 0, "All Year ", 36, false));
fl.add(new FishData("Horseshoe Crab ", 7, "All Year except May ", 60, false));
fl.add(new FishData("Haddock ", 18, "All Year ", 0, true));
fl.add(new FishData("Tautog ", 16, "late Spring to end of year ", 3, true));



I have to use an iterator to remove all of the false elements from this list and print it again. I think i understand how it works logically, if my data items were only comprised of booleans i think what i did would work, however i dont know how to look at just the boolean field of the element and remove it if its false. this is what i tried and got a class cast exception, i know what that means i just dont know how to fix it.


Iterator itr = fl.iterator();
while (itr.hasNext())
boolean w = (boolean) itr.next();
if (w = false)
itr.remove();









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard