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

View all comments

4

u/iPissVelvet Jul 27 '19

Study up on the following topics:

  • Static vs dynamic type (Java)

  • Inheritance (Java)

And then look at the Javadocs for Arraylist.