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
How To Eat An Elephant In Java
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
elephant.bite! until elephant.eaten?You guys are silly.Snippets Manager replied on Tue, 2008/03/04 - 12:34pm
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...?