0

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

3
  • Read the ArrayList class Commented May 20, 2018 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. Commented May 20, 2018 at 16:48
  • Interfaces need an implementation chosen. Commented May 20, 2018 at 16:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.