An alternative to loop constructs in Java Java allows methods to make recursive calls.  This can be dangerous because an infinite recursive call will fill up the stack. It can be useful, however, for calculations that need iteration when the number of "self calls" is limited (it save a few keystrokes as well). The code below, although not very useful, does demonstrate the technique.  What are some more practical uses of this technique and how could this code be modified for those uses?

class NoForLoop {
        int sayHello(int num) {
            System.out.println("Hello World!");
            return (1 &gt; num) ? 1 : sayHello(num -1); //self call
        }
    public static void main (String [] args) {
        NoForLoop n = new NoForLoop();
        n.sayHello(5);
    }
}
In Java 8 you can use streams, they tend to make the code quite more compact:

IntStream.range(0, 5).forEach(i -&gt; System.out.println("Hello World!"));


I would recommend reading the documentation of IntStream and Streams in general