Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) {

        List<String> friends = Arrays.asList("A", "B", "C", "D");

        //external iterate with index == evil
        for (int i = 0; i < friends.size(); i++) {
            System.out.println(friends.get(i));
        }

        //external iterate on collection, better but ... external
        for (String friend : friends) {
            System.out.println(friend);
        }

        //lambda
        friends.forEach(s -> System.out.println(s));

        //lambda reference
        friends.forEach(System.out::println);
    }

}