Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using an Iterator to filter an arbitrary Collection  RSS feed

 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Vijitha Kumara
Saloon Keeper
Posts: 3998
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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...
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's basically a method, with a signature like this:
 
Jeff Cortez
Greenhorn
Posts: 6
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijitha and Rob. Thank you.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!