Thomas (boggyb) wrote,
Thomas
boggyb

  • Mood:
  • Music:

A true gentleman leaves no puzzle unsolved

Okay, so it turns out that talismancer's post yesterday was filler. The moral balance has swung back!

As tempting as it is to fulfill the entirety of NaBloPoMo with us commenting on each other's posts, I feel like I should actually write something. So in the interests of increasing audience participation, I shall set a Java puzzler.

The puzzler consists of the following class:

import java.util.ArrayList;

public class Foo {
    private ArrayList<Object> barList = new ArrayList<Object>();

    public void fillBarList() {
        for (int i = 0; i < 10; i++) {
            Object o = new Object();
            System.out.println("Adding " + o + " at index " + i);
            barList.add(o);
        }
    }

    public void emptyBarList() {
        for (Object o : barList) {
            System.out.println("Removing " + o);
            barList.remove(o);
        }
    }

    public static void main(String[] args) {
        Foo f = new Foo();
        f.fillBarList();
        f.emptyBarList();
    }
}

Without running it (because that would be cheating and you will be mocked for it), what do you think will happen when Foo.main() is called?

Tags: java, nablopomo, programming, puzzle
Subscribe

  • NaBloPoMo!

    It's November, which means it's time for anther month of semi-coherent ramblings! Ironically, despite the current Covid insanity today was much like…

  • NaBloPoMo!

    Yes, it's that time of year where I try to create an entire month's worth of random ramblings! Today ended with a surprise games evening, courtesy…

  • Arduino thermometer

    What with the glorious sunny weather, I wondered how hot my flat actually gets. It's certainly felt far too warm recently. Now, the sensible way to…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments