• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 22781
131
Eclipse IDE Spring VI Editor 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: 22781
131
Eclipse IDE Spring VI Editor 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
reply
    Bookmark Topic Watch Topic
  • New Topic