File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes syntax question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "syntax question" Watch "syntax question" New topic
Author

syntax question

kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
in tutorial on Collections from java.sun:

The following method shows you how to use an iterator to filter an arbitrary Collection (that is, traverse the collection removing specific elements):



please what does "!cond" mean?

[ November 11, 2005: Message edited by: kwame Iwegbue ]
[ November 11, 2005: Message edited by: kwame Iwegbue ]

Who dares, wins! (SAS motto)
Jody Brown
Ranch Hand

Joined: Nov 09, 2005
Posts: 43
I would assume it is just some arbitary condition that, if is not true (the "!" part beforehand), then the instance is removed from the collection. The condition could be anything - a !=7, xyz!=12345.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791


Work from the inside out here.

i.next() gets the next value from the iterator.

cond( i.next() ) calls a method called "cond" passing that value as a parameter. cond() apparently returns a boolean.

!cond turns into the opposite boolean value. If cond returns true, the if test fails. If cond returns false, the if test passes.

Does that help?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
helps a whole bunch. Thanks once again guys. Always get confused by nested statements; also by "!"

[ November 11, 2005: Message edited by: kwame Iwegbue ]

why could'nt it just be-



[ November 11, 2005: Message edited by: kwame Iwegbue ]
[ November 11, 2005: Message edited by: kwame Iwegbue ]
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
Cause this way the for loop will remove every object in the collection, the cond function lets you specify the condition that the object must not fulfill in order to be removed. Lets say its your filter, only the objects that fail the condition will be removed


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: syntax question