Java's List Interface

667 Views Asked by At

This is a very simple question.

I have seen explanations on List and it says it is an Interface. I also understand how the List (arraylist) is used.

But my question, if List is an Interface, then why do not we use the keyword implements to use List?

4

There are 4 best solutions below

0
kosa On BEST ANSWER

If you would like to provide your own implementation for List, yes you can implement.

ArrayList is one of the implementation for List and yes it does implement the List interface.

0
Matt Ball On

Because you only use implements when writing your own implementation of an interface, and I assume you're not doing that for java.util.List.

0
jahroy On

If you read the source code for ArrayList, you will definitely find the following at the top of the file:

class ArrayList implements List

0
fastcodejava On

You need to understand the concept of interface in Java. There are many classes which implements the List interface and you can use whichever suits your need. Arraylist is one such example.