Why is it List<integer> list = new ArrayList();? shouldnt the first one be ArrayList instead of List? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it List<integer> list = new ArrayList();? shouldnt the first one be ArrayList instead of List?

28th Jan 2016, 10:19 PM
Branko Nešić
4 Answers
+ 2
List is interface which ArrayList and LinkedList implemented and we can use List when we don't sure which specific implementation will be used in one of situations later.
8th Feb 2016, 7:26 PM
Юрий Барсуков
Юрий Барсуков - avatar
+ 1
list is an Interface and Arraylist and linkedList are Implementation class for List interface. . u can aslo use like this ArrayList<Integer>=new ArrayList<Integer>(); or List=new Arraylist(); both are use to create ArrayList.. 1st one is Generic version and second one is Non generic
6th Nov 2016, 6:22 PM
Mukesh Kumaar
Mukesh Kumaar - avatar
0
As List has an Arraylist...i.e Arraylist implements List
28th Feb 2016, 12:33 PM
Ketan K. Ghatole
- 1
It likes Animal a = new Dog(); The first is superclass ,and the second is subclass.
7th May 2016, 4:14 PM
Zin Min Tun
Zin Min Tun - avatar