java.util.Objects
操作对象的工具类。
// 判断两个对象内容是否相同,null安全
public static boolean equals(Object a, Object b)
// 判断两个对象内容是否相同,null安全,对数组深度判断
public static boolean deepEquals(Object a, Object b)
// 计算hash值,null安全
public static int hashCode(Object o)
// 计算多个对象的hash值,null安全
public static int hash(Object... values)
// 转换对象为字符串,null安全
public static String toString(Object o)
// 转换对象为字符串,提供null情况的输出字符串
public static String toString(Object o, String nullDefault)
// 比较大小
public static <T> int compare(T a, T b, Comparator<? super T> c)
// 验证对象非null,如果是null抛出异常
public static <T> T requireNonNull(T obj)
public static <T> T requireNonNull(T obj, String message)
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier)
// 判断对象是否是null
public static boolean isNull(Object obj)
// 判断对象不是null
public static boolean nonNull(Object obj)
java.util.Collections
操作集合的工具类。
// 列表排序
public static <T extends Comparable<? super T>> void sort(List<T> list)
public static <T> void sort(List<T> list, Comparator<? super T> c)
// 列表二分查找
public static <T> int binarySearch(List<? extends Comparable<? super T>> list, T key)
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c)
// 反转元素顺序
public static void reverse(List<?> list)
// 随机打乱元素顺序
public static void shuffle(List<?> list)
public static void shuffle(List<?> list, Random rnd)
// 列表元素值填充
public static <T> void fill(List<? super T> list, T obj)
// 复制列表元素值
public static <T> void copy(List<? super T> dest, List<? extends T> src)
// 集合最小值
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp)
// 集合最大值
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)
// 列表元素循环旋转
public static void rotate(List<?> list, int distance)
// 元素替换
public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal)
// 返回反转的比较器
public static <T> Comparator<T> reverseOrder()
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
// 集合中元素出现次数
public static int frequency(Collection<?> c, Object o)
// 返回两个集合交集是否为空
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
// 添加元素到集合
public static <T> boolean addAll(Collection<? super T> c, T... elements)
java.util.Arrays
操作数组的工具类。
// 数组排序,快速排序或者归并排序
public static void sort(int[] a)
public static void sort(long[] a)
public static void sort(short[] a)
public static void sort(char[] a)
public static void sort(byte[] a)
public static void sort(float[] a)
public static void sort(double[] a)
public static void sort(Object[] a)
// 数组部分排序
public static void sort(int[] a, int fromIndex, int toIndex)
...
// 有序数组上进行二分查找
public static int binarySearch(int[] a, int key)
...
// 两个数组相等比较
public static boolean equals(int[] a, int[] a2)
public static boolean deepEquals(Object[] a1, Object[] a2)
...
// 数组元素值填充
public static void fill(int[] a, int val)
...
// 数组扩容
public static int[] copyOf(int[] original, int newLength)
...
// 数组复制
public static int[] copyOfRange(int[] original, int from, int to)
...
// 数组转换为List
public static <T> List<T> asList(T... a)
// 数组计算hash值
public static int hashCode(int a[])
public static int deepHashCode(Object a[])
...
// 数组转换为字符串
public static String toString(int[] a)
public static String deepToString(Object[] a)
...
// 数组转换为对应的Stream流
public static IntStream stream(int[] array)
...
java.nio.file.Paths
public static Path get(String first, String... more)
public static Path get(URI uri)
java.nio.file.Files
操作文件的工具类。
// 创建输入流
public static InputStream newInputStream(Path path, OpenOption... options)
// 创建输出流
public static OutputStream newOutputStream(Path path, OpenOption... options)
// 创建文件
public static Path createFile(Path path, FileAttribute<?>... attrs)
// 创建目录
public static Path createDirectory(Path dir, FileAttribute<?>... attrs)
public static Path createDirectories(Path dir, FileAttribute<?>... attrs)
// 创建临时文件
public static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>... attrs)
public static Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs)
// 创建软连接文件
public static Path createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
// 删除文件
public static void delete(Path path)
public static boolean deleteIfExists(Path path)
// 复制文件
public static Path copy(Path source, Path target, CopyOption... options)
// 移动文件
public static Path move(Path source, Path target, CopyOption... options)
// 是否是隐藏文件
public static boolean isHidden(Path path)
// 推测文件内容类型
public static String probeContentType(Path path)
// 是否是软连接、目录、普通文件
public static boolean isSymbolicLink(Path path)
public static boolean isDirectory(Path path, LinkOption... options)
public static boolean isRegularFile(Path path, LinkOption... options)
// 获取文件最近修改时间
public static FileTime getLastModifiedTime(Path path, LinkOption... options)
// 获取文件大小
public static long size(Path path)
// 判断文件是否存在
public static boolean exists(Path path, LinkOption... options)
public static boolean notExists(Path path, LinkOption... options)
// 文件是否可读、可写、可执行
public static boolean isReadable(Path path)
public static boolean isWritable(Path path)
public static boolean isExecutable(Path path)
// 文件与流拷贝
public static long copy(InputStream in, Path target, CopyOption... options)
public static long copy(Path source, OutputStream out)
// 读取文件内容
public static byte[] readAllBytes(Path path)
public static List<String> readAllLines(Path path, Charset cs)
public static List<String> readAllLines(Path path)
// 写内容到文件
public static Path write(Path path, byte[] bytes, OpenOption... options)
public static Path write(Path path, Iterable<? extends CharSequence> lines, Charset cs, OpenOption... options)
public static Path write(Path path, Iterable<? extends CharSequence> lines, OpenOption... options)
// 按行返回文件内容的Stream流
public static Stream<String> lines(Path path, Charset cs)
public static Stream<String> lines(Path path)
java.lang.System
// 获取当前系统时间戳,毫秒
public static native long currentTimeMillis()
// 获取当前系统时间,纳秒
public static native long nanoTime()
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
// 加载本地库,C/C++库
public static void load(String filename)
public static void loadLibrary(String libname)
java.util.Base64
Base64编码与解码。
public static Encoder getEncoder()
public static Decoder getDecoder()
java.util.Base64.Encoder
public byte[] encode(byte[] src)
public int encode(byte[] src, byte[] dst)
public String encodeToString(byte[] src)
java.util.Base64.Decoder
public byte[] decode(byte[] src)
public byte[] decode(String src)
public int decode(byte[] src, byte[] dst)
java.lang.Math
数学相关工具类。
public static double sin(double a)
public static double cos(double a)
public static double tan(double a)
public static double exp(double a)
public static double log(double a)
public static double log10(double a)
public static double sqrt(double a)
public static double pow(double a, double b)
public static double ceil(double a)
public static double floor(double a)
public static long round(double a)
public static int abs(int a)
public static int max(int a, int b)
public static long min(long a, long b)
public static float min(float a, float b)
public static double min(double a, double b)
public static int min(int a, int b)
public static long max(long a, long b)
public static float max(float a, float b)
public static double max(double a, double b)
java.util.concurrent.ThreadLocalRandom
随机数相关。
public static ThreadLocalRandom current()
public int nextInt()
public int nextInt(int bound)
public int nextInt(int origin, int bound)
public long nextLong()
public long nextLong(long bound)
public long nextLong(long origin, long bound)
public double nextDouble()
public double nextDouble(double bound)
public double nextDouble(double origin, double bound)
public double nextGaussian()
java.util.UUID
UUID生成。
public static UUID randomUUID()
public static UUID nameUUIDFromBytes(byte[] name)
public static UUID fromString(String name)