Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

syntax question

 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jody Brown
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic