devxlogo

March 28, 2001

Object.hashCode() and Object.equals()

The Object.hashCode() method returns a number that is effectively random. This number is also implementation- and instance-dependent. This has a couple consequences: 1 – The order of iteration for elements

Making a Collection Read-Only

The Collections class provides static APIs to generate a read-only or unmodifiable collection, list, set, or map from the specified entity. For instance, if you are sure that the ArrayList

Making a Thread-Safe or Synchronized Collection

As you know by now, the commonly used collection classes, such as java.util.ArrayList, are not synchronized. However, if there’s a chance that two threads could be altering a collection concurrently,

Conditional Compilation in Java

The C preprocessor provides for conditional compilation in instances where large areas of text are ignored and stripped out, regardless of whether a given preprocessor constant was defined. For example: