DEV Community

Discussion on: Java Lists: Lists of Lists

Collapse
 
pawelsalawa profile image
Pawel Salawa • Edited

Few suggestions/advises:

  1. Use diamond operator to simplyfiy generic collections creation. For example: ArrayList<ArrayList<Integer>> list = new ArrayList<>();
  2. Use generalized types for declaration, unless you have good reason to use specific types. For example: List<List<Integer>> list = new ArrayList<>();
  3. In most cases the "foreach" of Java is suffficient to iterate through collection. The C-like style with indexes is still applicable in some cases, but you will mostly use the "foreach": for (List<integer> subList : list) {...}