Content deleted Content added
Ztothefifth (talk | contribs) m →Collection Interface: contains() method |
Ztothefifth (talk | contribs) new section on List interface |
||
Line 9:
==Collection Interface==
All collections in Java are derived from the Collection interface. Collection defines the basic parts of all collections. The interface states the add() and remove() methods for adding to and removing from an interface respectively. Also required is the toArray() method, which converts the collection into a simple array of all the elements in the collection. Finally, the contains() method checks if a specified element is in the collection. The Collection interface is a subinterface of Iterable, so the iterator() method is also provided. All collections have an iterator that goes through all of the elements in the collection. Additionally, Collection is a generic. Any collection can be written to store any class. For example, Collection<String> can hold strings, and the elements from the collection can be used as strings without any casting required.
==List Interface==
Lists are implemented in the JCF via the List interface. It defines a list as essentially a more flexible version of an array. Elements have a specific order, and duplicate elements are allowed. Elements can be placed in a specific position. They can also be searched for within the list. Two concrete classes implement List. The first is ArrayList, which implements the list as an array. Whenever functions specific to a list are required, the class moves the elements around within the array in order to do it. The other implementation is LinkedList. This class stores the elements in nodes that each have a pointer to the previous and next nodes in the list. The list can be traversed by following the pointers, and elements can be added or removed simply be changing the pointers around to place the node in its proper place.
== See also ==
|