Collections Section Index | Page 6
What is the function of a load factor in a Hashtable?
The load factor determines how full a hashtable may get before it expands its capacity. I think that the comments on the Hashtable API docs explain it very well:
The load factor is a measure of h...more
What is a WeakHashMap? What is its use and when should you use it?
A WeakHashMap is a special Map implementation where the keys of the map are stored in a java.lang.ref.WeakReference. By storing the keys in a weak reference, key-value pairs can dynamically be dro...more
What is stable sorting?
The collections framework specification requires that the sorting
algorithms be stable. Stated succinctly, a sorting algorithm is stable
if it does not reorder equal elements. But what does that r...more
How do you sort the elements of a vector?
Since the Vector class implements the List interface, you can call the Collections.sort() method to sort the elements in place. You can also manually insert elements into a Vector to keep the vect...more
What is a fail-fast iterator?
An iterator is considered fail-fast if it throws
a ConcurrentModificationException under either of
the following two conditions:
In multithreaded processing: if one thread is trying to modify a
...more
What is meant by natural ordering of objects in the context of the collections framework?
Java documentation refers to the natural ordering of objects
when describing various algorithms and data structures in the
collections framework. Object ordering is obviously needed by the
sorting...more
What is a polymorphic algorithm?
In general, an algorithm is called polymorphic if it can achieve the same functionality using different data structures. For example, if the same sorting or searching algorithm could be used with ...more
What is the difference between a singly linked list and doubley linked list?
A singly linked list is one that has only a pointer/reference to the next element in the list. A doubley linked list has both a previous and next pointer/reference.
How do I treat an object I get out of a Vector (collection) as the type I put into it?
When you get an object out of a Vector (or any collection), the object is returned as being of type Object. You need to cast it back into the object type you put into the data structure if you nee...more
Do the keys() and elements() methods of a Hashtable enumerate things in the same order?
There is no requirement that the elements are returned in the same order, only that all of them are returned in the Enumeration. Your best bet for getting the element for a key is to loop through ...more
How do I read input from a stream "one word at a time"?
What you need to do is use the java.util.StringTokenizer or java.io.StreamTokenizer to parse your input into words. Each has a default set of delimiters like white space that can be changed. The f...more
Where can I find additional implementations of the Collections Framework API?
Doug Lea offers several implementations of collection framework interfaces in his library that help overcome concurrency problems.
You can also check out the Java Collections Clearinghouse.
If yo...more
Where can I find Java packages for expressing numerical formulas?
Colt offers, among others, efficient and usable data structures and algorithms for Off-line and On-line Data Analysis, Linear Algebra, Multi-dimensional arrays, Statistics, Histogramming, Monte Ca...more
What are the differences between ArrayList and LinkedList?
An ArrayList is a List implementation backed by a Java array, similar to the Vector class. As the number of elements in the collection increases, the internal array grows to fit them. If there are...more
Which collections in Java are synchronized and which aren't?
The original collection classes in Java are all synchronized: Vector and Hashtable, along with their subclasses Stack and Properties. Those classes introduced with the Java 2 Collections Framework...more