Collections Section Index | Page 5
This depends on what version of Java you are using. For JDK 1.2, the size was 101. For JDK 1.3, the size changed to 11.
The Java Collections Clearinghouse maintains references to different implementations of the Collection Framework interfaces.
As referenced from the Java Collections Clearinghouse, you can find a priority queue implemented as part of MIT's FLEX compiler imfrastructure. Source code is licensed under the GNU GPL. There is ...more
Unlike Vector where you can specify a capacity increment, ArrayList doesn't support this. Instead, ArrayList will increase capacity by about a half when it runs out of space. The refernece impleme...more
What is the minimum number of key-value pairs for which it makes sense to use a HashMap, as opposed to using a pair of arrays (one for keys, the other for values) with brute-force key searches?
What is the minimum number of key-value pairs for which it makes sense to use a HashMap, as opposed to using a pair of arrays (one for keys, the other for values) with brute-force key searches?Many...more
Normally the Java garbage collector plays safe. It will only free up the memory used by an object when that object can no longer be accessed by the program. Once an object become impossible to rea...more
When I wrap a collection to be read-only or synchronized, why can't I call any of the collection methods via reflection without getting an IllegalAccessException?
When you wrap a collection through the static methods of the Collections class, this creates an instance of a package-private (default access) class. Because you don't have access to these classes...more
Since Properties extends Hashtable, can I use the Hashtable methods to add elements to a Properties list?
Technically speaking you can. However, you have to make sure you only add key-value pairs where both are strings. If you add something other than a String, the listing, loading, and saving methods...more
In order for the Java Collections to work properly (and everything else in Java), the equals() and hashCode() methods must be compatible. Here, compatible means that if equals() reports that two i...more
This will cause a stack overflow exception to be generated on calls to methods like toString() and hashCode(), which recursively call the method on the elements of the collection.
There is no public interface to access the load factor setting. Some choices you can do to expose this value... Subclass Hashtable and add a read-only accessor method Use reflection to access the...more
Starting with the 1.3 release of Java, the java.lang.String class will only calculate the hashcode once, when its first needed. Future calls to hashCode() will return the previously calculated value.more
Within the JavaMail classes there is no support for this. However, once you get the array of messages back from a folder, you can call the Arrays.sort() method in the collections framework to sort...more
Until there is support for generic types in Java, you'll need to create a collection that overrides the methods that add elements into the collection. In these methods, you would check for the app...more
The vector constructor can include either an initial capacity or a capacity and growth increment. When not specified, the initial size of the vector is 10 and growth will double when necessary. Ot...more