Collections Section Index | Page 9
How do I create linked lists if there are no pointers?
No pointers does not mean no reference variables. You just can't deference them as you can in C/C++ or perform pointer arithmetic. You can still use abstract data types that require dynamic data s...more
How do I make an array larger?
You cannot directly make an array larger. You must make a new (larger) array and copy the original elements into it, usually with System.arraycopy(). If you find yourself frequently doing this, th...more
How do I sort objects into their reverse natural ordering?
The Collections.reverseOrder() method returns a Comparator that sorts objects that implement the Comparable interface in reverse order.
How do I use an array with the Collections Framework?
The Arrays.asList() method provides a fixed-length List view of an array, where changes to the List are stored in the original array. The Arrays class also provides additional support methods for ...more
How do I use Enumeration to iterate through a collection?
Enumeration enum = ...;
while (enum.hasMoreElements()) {
Object element = iterator.nextElement();
// process element
}
How do you store a primitive data type within a Vector or other collections class?
You need to wrap the primitive data type into one of the wrapper classes found in the java.lang package, like Integer, Float, or Double, as in:
Integer in = new Integer(5);
more
The TreeMap documentation states that it is a red-black tree based implementation of the SortedMap interface. What are red-black trees?
A red-black tree is a binary search tree where every node has two children or is a leaf. It ensures O(log N) search times, at a cost of a more complicated insertion (and deletion) process. In a re...more
What newsgroups/mailing lists are available to ask questions about the Collections Framework?
The comp.lang.java.programmer newsgroup is probably your best bet for Collections Framework questions. There is mailing list specific to ObjectSpace JGL-questions that you can subscribe to at http...more
Where can I get the Collections Framework?
The Collections Framework is a core part of the Java 2 platform. You don't have to download anything more than the Java 2 SDK. For more information about the framework, the main documentation is a...more
Which is faster, synchronizing a HashMap or using a Hashtable for thread-safe access?
Because a synchronized HashMap requires an extra method call, a Hashtable is faster for synchronized access.