I know that when I add an object to some collections such as a LinkedList, the element is not added directly to the collection; in actuality a node is added to the collection which provides the linking functionality, and this node has a reference to the Object that I add to the collection. Is this true for all Java collection classes? For example when I do the following:
List<String> list = new ArrayList<String>();
list.add("Car");
Is the String object “Car” added directly to the list, or just a node is added to the list which points to “Car”?
Also, can I consider this a proxy design pattern?
ArrayList in Java uses array to store the references to objects, thus it has nothing to do with Proxy pattern. You can see that for yourself, here is a link to it’s OpenJDK implementation. Line 103 has the relevant piece of code.
You can also compare it to LinkedList which uses Nodes to store references to next and previous element in
List.