20230531 java.util.Objects
介绍
java.util.Objects
public final class Objects
API
static
- equals
- deepEquals
- 比较数组元素
- hashCode
- hash
- 为一系列输入值生成哈希码
- toString
String toString(Object o)
String toString(Object o, String nullDefault)
- compare
<T> int compare(T a, T b, Comparator<? super T> c)
null 判断,抛出 NullPointerException
- isNull
- nonNull
- requireNonNull
<T> T requireNonNull(T obj)
<T> T requireNonNull(T obj, String message)
<T> T requireNonNull(T obj, Supplier<String> messageSupplier)
- requireNonNullElse
<T> T requireNonNullElse(T obj, T defaultObj)
- requireNonNullElseGet
<T> T requireNonNullElseGet(T obj, Supplier<? extends T> supplier)
检查索引越界,抛出 IndexOutOfBoundsException
- checkIndex
int checkIndex(int index, int length)
long checkIndex(long index, long length)
- checkFromToIndex
int checkFromToIndex(int fromIndex, int toIndex, int length)
long checkFromToIndex(long fromIndex, long toIndex, long length)
- checkFromIndexSize
int checkFromIndexSize(int fromIndex, int size, int length)
long checkFromIndexSize(long fromIndex, long size, long length)