i've been wondering how does the interface List in java store data. An interface is a set of methods that must be implemented by a class (please correct if i'm wrong) and thus a list can't have variables to store data.
For instance, List<Integer> list1 = new ArrayList<>(); list1.add(5);
where will the integer 5 be stored ? Does the list1 use the ArrayList's attributes to store data ? What really happens when i create an interface ? Does it create an object of a certain class to operate on it ?
Thank you
Asked
Active
Viewed 530 times
0

Ousmane D.
- 54,915
- 8
- 91
- 126

Ahmed Gharbi
- 1
- 1
-
Read the ArrayList class – Mạnh Quyết Nguyễn May 20 '18 at 16:46
-
As you already noticed, the `List` interface can not store data. But the `ArrayList` can and stores the data in an array. A `LinkedList` stores that information as linked list. But you can use both of them interchangeable when you only use the `List` interface. – Johannes Kuhn May 20 '18 at 16:48
-
Interfaces need an implementation chosen. – Thorbjørn Ravn Andersen May 20 '18 at 16:54