
上QQ阅读APP看书,第一时间看更新
Getting ready
The Objects class has only 17 methods, all of which are static. For a better overview, we have organized them into seven groups:
- compare(): One method compares two objects using the provided Comparator
- toString(): Two methods that convert an Object to a String value
- checkIndex(): Three methods that allow us to check whether the index and the length of a collection or an array are compatible
- requireNonNull(): Five methods throw an exception if the provided object is null
- hash(), hashCode(): Two methods that calculate a hash value for a single object or an array of objects
- isNull(), nonNull(): Two methods that wrap the obj == null or obj != null expressions
- equals(), deepEquals(): Two methods that compare two objects that can be null or arrays
We are going to write code that uses these methods in the preceding sequence.