I have the code:
List<Integer> grades = new ArrayList<Integer>();
ArrayList<Integer> grades1 = new ArrayList<>();
what is the difference between the first way of initializing an ArrayList and the second way?
I have the code:
List<Integer> grades = new ArrayList<Integer>();
ArrayList<Integer> grades1 = new ArrayList<>();
what is the difference between the first way of initializing an ArrayList and the second way?
Essentially, ArrayList is a kind of List, which means, as NomadMaker pointed out, ArrayLists can be initialized into Lists.
List<Integer> grades = new ArrayList<Integer>();
If you plan on changing grades
to a different kind of list, you will want to use List<>
, otherwise there's no difference.