Java collections framework: Difference between revisions

Content deleted Content added
Collection Interface: added info on iterators and generics
m Collection Interface: contains() method
Line 8:
 
==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.
 
== See also ==