r/learnjava • • Jul 27 '19

Is there a difference between declaring an Arraylist with List<> and with ArrayList<> ?

I learnt it as the latter and hadnt seen the first one until recently. I was trying a Leetcode question where the return type was given as List<Integer>. Returning an ArrayList which was declared using ArrayList<Integer> gave me a compilation error. So whats the exact difference between the two?

48 Upvotes

4 comments sorted by