Never been to DZone Snippets before?

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

How to eat an elephant in Java (See related posts)

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 on this post

alxx posts on Apr 08, 2008 at 13:45
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...?
ChronicStar posts on Apr 09, 2008 at 20:10
Haha, when I read the OP I was thinking something like:
elephant.bite! until elephant.eaten?

You guys are silly.

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts