![]() ![]() ![]() ![]() |
| ![]()
|
|
| ![]() ![]() ![]() |
|
Visio class diagram:
![]() |
| ![]() ![]() ![]() |
|
Write code that declares, constructs and initializes arrays of any base type using any of the permitted forms, both for declaration and for initialization.
| ![]() ![]() ![]() |
![]()
Each additional level in the subclass makes more methods available. For example, when an ArrayList is instantiated by extending AbstractList and implementing List, it inherits methods of the Collection interface because AbstractList extends the AbstractCollection interface, which provides the toString() method. Abstract classes allow a collection to implement optional methods. To make a collection modifiable, simply override the set( object ) method. To make a collection grow, override the add( object ) and remove( int index) methods. New elements are added immediately prior to the implicit cursor. After adding an element, calling previous() returns the new element and calling next() returns what would have been the next element prior to the add operation.
To make a twoi-dimensional array, define an array within an array, such as:
or String[] [] FirstName = new String[14] []; | ![]() ![]() |
| ![]() ![]() ![]() |
|
Collection Interface | New Class | Usage | Arguments & Additional Methods |
---|---|---|---|
![]() List overloads add() with add(int, Object) and addAll( collectionC ) to insert objects at the specified index. | ArrayList | extends AbstractList for a resizable Random Access array that's not synchronized. Cloneable. | constructor argument can be a collection or int Capacity, also in ensureCapacity()
|
Vector | expandable array of sequenced objects. Modified to implement Collection. Synchronized. | ||
Stack | A form of Vector to push LIFO (Last-In, First-Out) pop | ||
LinkedList | extends AbstractSequentialList so each element references the next and previous element to emulate Stack, queue, and other end-oriented data structures. This doubly linked chain of objects speeds inserts/deletes but slows indexing. | Use xxxFirst() to add, get, or remove at the beginning and xxxLast() at the end. | |
![]() |
TreeSet implements SortedSet.
Its constructor argument can be a collection, Comparator, or Sorted Set. | a sorted binary tree of objects stored in ascending order. Does not allow duplicates. Cloneable. | |
HashSet | Unsorted, so no duplicates or null values. Cloneable. | constructor argument capacity of elements plus a fillRatio between 0.0 and 1.0. | |
LinkedHashSet | New to 1.4. Extends HashSet for insertion-order iterations. | ||
![]() A map can store duplicate objects, but not with duplicate keys. It replaces the Dictionary class deprecated in 1.2.
It is implemented by classes HashTable and HashMap.
| TreeMap implements SortedMap | stores objects in an ascending order of their keys, so it automatically sorts objects to the default Comparator. | |
HashMap | reference by key. Not synchronized like Hashtable of Dictionary. Allows nulls. | Uses .equals() to compare. | |
WeakHashMap | entry vanishes when its key is no longer reachable by any thread. 1.3 adds a constructor to accept a Map. | ||
IdentityHashMap | New to 1.4. | Uses the == operator instead of equals() method to compare. |
BitSet, an array of boolean bits, is not a set and not part of the Collections framework.
| ![]() ![]() ![]() |
| ![]()
The hierarchy of classes of the java.lang.Object package are: Dictionary-Stores key-value pairs.
| ![]() ![]() ![]() |
Related:
![]()
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page ![]() Thank you! |