Interface collection

Collection is the top of the interface hierarchy. This interface defines the methods that all implementations should provide, no matter if they implement the Set, SortedSet, List, Queue, or Deque interface directly. As Collection simply says that an object that implements the Collection interface is only an object that collects other objects together, the methods it defines are like adding a new object to the collection, clearing all elements from there, checking that an object is already a member of the collection, and iterating through the elements.

For an up-to-date definition of the interface, consult the Java pi documentation (http://download.java.net/java/jdk9/docs/api/overview-summary.html). You can consult the online API any time, and it is recommended to do so.

The Java language itself directly supports the interface. You can iterate through the elements of the Collection with the enhanced for loop syntax, the same way as you can iterate over the elements of an array where the collection should be an expression that results an object that implements the Collection interface:

for( E element : collection ){...}

In the preceding code, E is either Object or the generic type of the elements of the Collection.

The interface Collection is not directly implemented in the JDK. Classes implement one of the sub interfaces of Collection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.37.10