aspose file tools
The moose likes Java in General and the fly likes please explain the statement f (!cond(it.next())) from the mentioned piece of code. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "please explain the statement f (!cond(it.next())) from the mentioned piece of code." Watch "please explain the statement f (!cond(it.next())) from the mentioned piece of code." New topic
Author

please explain the statement f (!cond(it.next())) from the mentioned piece of code.

gauravkv gupta
Greenhorn

Joined: Feb 18, 2012
Posts: 21
hi,

On the tutorial provided by Sun, following example is used. I am not getting the meaning of "f (!cond(it.next()))" in the piece of code.

static void filter(Collection<?> c) {
for (Iterator<?> it = c.iterator(); it.hasNext(); )
if (!cond(it.next()))
it.remove();
}

Please explain the "cond". What is meant by this?

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

Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 186
gauravkv gupta wrote:
Please explain the "cond". What is meant by this?


Assume it as a function which return false whenever there is a need to remove a specific element of a Collection otherwise true.

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

static void filter(Collection<?> c) {
for (Iterator<?> it = c.iterator(); it.hasNext(); )
if (!cond(it.next()))
it.remove();
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
. . . or true whenever you should leave that element in the list
The cond() method ought to be somewhere in your class, or a static import.
James Boswell
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2

cond() would be a user-defined method which would return a boolean to indicate if the given element should remain in the collection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please explain the statement f (!cond(it.next())) from the mentioned piece of code.
 
Similar Threads
What is greater than less than?
syntax question
Using an Iterator to filter an arbitrary Collection
Ant command to know whether machine/OS is 32 bit or 64 bit ?
Static