-1

Usually declaration type is interface type and initialization part has implementation type. what is differnce between List<String> list = new ArrayList<String> and ArrayList<String> list = new ArrayList<String>? What is difference beside polymorphism?

Tom
  • 16,842
  • 17
  • 45
  • 54
  • 2
    Hint: it took me less than 10 seconds to find this answer. Next time, please **you** try to do that prior research. – GhostCat Dec 23 '16 at 09:32

2 Answers2

1

There are no important differences. But if you use something like this

void doSomething(List list)
{}

you can use any object which extends the List class, but if you use something like this void doSomething(ArrayList list) {} you can use only ArrayList object and its subclasses.

Ihor Dobrovolskyi
  • 1,241
  • 9
  • 19
0

List is an interface and ArrayList is its implimentation class. We can't create object of interface because they are abstract but we can create reference of interface which is nothing but List list . Using this reference we can invoke methods of ArrayList.

  • This doesn't answer the question. It doesn't answer the differences between using `List<..>` or `ArrayList<..>` as variable type. – Tom Dec 23 '16 at 09:41