r/learnjava • u/ThiccShadyy • 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
u/clivethescott Jul 27 '19
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
https://docs.oracle.com/javase/8/docs/api/java/util/List.html