java collection framework jcf - ghdrako/doc_snipets GitHub Wiki

obraz The root classes are java.util.Collection and java.util.Map. While maps do contain collection-view operations, which enable them to be manipulated as collections, from a technical point of view, maps are not collections in Java.

The interface java.util.Collection is not implemented directly, rather Java has implementations of its sub interfaces. This interface is typically used to pass collections around and manipulate them with max degree of generality.

Insert elements into a collection

java.util.Collection permits us to insert elements in these ways:

  • boolean add(Element e) adds a new element E and ensures collection contains the specified element. So it returns either true or false depending if this collection changed as a result of the call.
  • boolean addAll(Collection c) inserts all elements from collection C to the collection. Note, that this method also returns boolean value, which stands true if this collection changed as a result of the call

Note, that both of these methods are defined as optional. methods From a technical point of view, that concrete implementations are permitted to not perform one or more of these operations (in such cases they throw UnsupportedOperationException when such operation is performed).