-2

I'm new to java learning. Right now learning about list and array list. While studying I've read out that list is nothing but an interface. Which creates an interface between an method and an object.(Correct me if am wrong.)

Secondly, ArrayList is itself is an a class and having own set of methods inside that.

While checking some java codes, found this statement.

List<String> MyList = new ArrayList<String>();

I just got to know further googleing, that if we create a list then we can use all of the methods inside ArrayList class on List we had just created.(Correct me if am wrong)

But am curious to know, cant imagine so that I could understand this statement. Does it mean MyList variable is created of List type and became an attribute of ArrayList Object. Does it make any sense what I said here..? I want to understand what it means and importance of using like this here ..!!

Shannin
  • 35
  • 6
  • It means that `ArrayList` _implements_ `List`. It has all of the behavior required to be considered a `List`. It is not actually possible to create a `List` but it you can have a variable of type `List` which actually refers to some instance of a class implementing `List` such as `ArrayList`. – Aluan Haddad May 14 '17 at 04:27
  • see this question : [What does “program to interfaces, not implementations” mean?](http://stackoverflow.com/q/2697783/2815219) – Raman Sahasi May 14 '17 at 04:29
  • @RamanSahasi..in link given by you...First answer says..."Any instance returned by the factory would be of type Interface which any factory candidate class must have implemented." Instance of Factory here means instance of ArrayList..? If yes then how Instance of ArrayList and Mylist List's variable are relating each other in my questions's code statement ? – Shannin May 14 '17 at 05:11

1 Answers1

0

List is an Interface and ArrayList is its implementation

You may want to refer the below links to understand the java interfaces and java collection framework for the basic understanding.

https://www.tutorialspoint.com/java/java_interfaces.htm

https://www.javatpoint.com/collections-in-java