• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Using an Iterator to filter an arbitrary Collection

 
Greenhorn
Posts: 6
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a complete beginner with Java. Here's a question I have about the Oracle Java tutorial:

http://download.oracle.com/javase/tutorial/collections/interfaces/collection.html

The following method shows you how to use an Iterator to filter an arbitrary Collection, that is, traverse the collection removing specific elements.


I don't see how !cond creates a boolean expression for the if statement. If the collection holds references of type Boolean I understand that


would remove, using the above snippet, any elements that are False.

Or if the collection holds Strings and you want to remove "cat" you could write


But what is the meaning of 'cond' in the tutorial? Is it an undefined condition? If so, the example in the tutorial seems to me unclear or a bug.

Thanks.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Jeff Cortez

Well, the code snippet is just a sample to show how it's done. The cond may represent a method which you could use to define a criteria/logic to be used for the objects of the Collection in order to be deleted...
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's basically a method, with a signature like this:
 
Jeff Cortez
Greenhorn
Posts: 6
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vijitha and Rob. Thank you.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic