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

syntax question

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic