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
Listinterface can not store data. But theArrayListcan and stores the data in an array. ALinkedListstores that information as linked list. But you can use both of them interchangeable when you only use theListinterface.