DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Chris has posted 1 posts at DZone. View Full User Profile

How To Eat An Elephant In Java

04.07.2008
| 3997 views |
  • submit to reddit
        How do you eat an elephant? Well, 'bite by bite', they told me. In Java, this may look like this:

  Elephant elephant = ...; // get the elephant from somewhere

  while (!elephant.isEatenCompletely()) {
    elephant.haveOneBite();
  }


Why am I writing this? Well, simply to test my dzone account ;)    

Comments

Snippets Manager replied on Wed, 2007/05/16 - 11:08pm

Haha, when I read the OP I was thinking something like: elephant.bite! until elephant.eaten? You guys are silly.

Snippets Manager replied on Tue, 2008/03/04 - 12:34pm

Proof that Ruby > Java: elephant.bites.each do { |bite| bite.eat! } elephant.each_bite do { |bite| bite.eat! } elephant.bites.map &:eat! elephant.have_one_bite until elephant.bites.empty? Should I go on...?