Java Arrays cookbook

By Maurizio Farina | Posted on September 2017

How initialize an ArrayList in one line?

1
2
3
4
5
ArrayList<String> citiesList = new ArrayList<String>() {{
        add("Naples");
        add("Rome");
        add("Milan");
}};