Author: Nesha Mason
-
Modifying Capacity – Collections, Part I: ArrayList
•
Modifying Capacity The following two methods can be used to modify the capacity of a list. There is no method that returns the current capacity of an ArrayList<E>. void trimToSize() Trims the capacity of this list to its current size. Click here to view code image void ensureCapacity(int minCapacity) From List<E>interface. Ensures…
-
Converting an ArrayList to an Array – Collections, Part I: ArrayList
•
12.6 Converting an ArrayList<E> to an Array The following methods are specified by the Collection<E> interface and can be used to convert a collection to an array. List and set implementations in the java.util package provide customized versions of the first two methods for this purpose. In this section we…
-
Wildcard Capture – Generics
•
11.9 Wildcard Capture As we have seen, a wildcard can represent a family of types. However, the compiler needs to have a more concrete notion of a type than a wildcard in order to do the necessary type checking. Internally, the compiler represents the wildcard by some anonymous but specific…