Avoid instanceof | Throwing and catching exceptions

Initial capacity and load factor

Specify reasonable initial capacities when creating container objects such as StringBuffers, Lists, Sets, Maps, Vectors, and Hashtables, to avoid unnecessary re-allocation when the initial capacity is exceeded, and to avoid allocating more memory than required.

The capacity for a StringBuffer created using the StringBuffer(String aString) constructor is 16+aString.length(). If you know that the StringBuffer will eventually be longer than that, you will be better off specifying an initial capacity for the StringBuffer and then appending aString.

For HashMaps and Hashtables, take the load factor into account when specifying initial capacities. For example, to allocate a HashMap with sufficient capacity for n entries (using the default load factor of .75), specify an initial capacity of 1+n*100/75.

We do not recommend increasing the default load factor (for example, to 1), since each hash bucket will end up holding more entries, thus slowing down the lookup operation.
xxxx