程序包 cn.wjybxx.base

类 ArrayUtils

java.lang.Object
cn.wjybxx.base.ArrayUtils

public class ArrayUtils extends Object
数组工具类
作者:
wjybxx date - 2024/7/19
  • 字段详细资料

    • INDEX_NOT_FOUND

      public static final int INDEX_NOT_FOUND
      另请参阅:
    • EMPTY_BYTE_ARRAY

      public static final byte[] EMPTY_BYTE_ARRAY
    • EMPTY_INT_ARRAY

      public static final int[] EMPTY_INT_ARRAY
    • EMPTY_LONG_ARRAY

      public static final long[] EMPTY_LONG_ARRAY
    • EMPTY_FLOAT_ARRAY

      public static final float[] EMPTY_FLOAT_ARRAY
    • EMPTY_DOUBLE_ARRAY

      public static final double[] EMPTY_DOUBLE_ARRAY
    • EMPTY_BOOLEAN_ARRAY

      public static final boolean[] EMPTY_BOOLEAN_ARRAY
    • EMPTY_STRING_ARRAY

      public static final String[] EMPTY_STRING_ARRAY
    • EMPTY_OBJECT_ARRAY

      public static final Object[] EMPTY_OBJECT_ARRAY
    • EMPTY_CLASS_ARRAY

      public static final Class<?>[] EMPTY_CLASS_ARRAY
  • 构造器详细资料

    • ArrayUtils

      public ArrayUtils()
  • 方法详细资料

    • indexOf

      public static <T> int indexOf(T[] list, Object element)
      查找对象引用在数组中的索引
    • lastIndexOf

      public static <T> int lastIndexOf(T[] list, Object element)
      反向查找对象引用在数组中的索引
    • indexOf

      public static <T> int indexOf(T[] list, Object element, int start, int end)
      参数:
      list - 数组
      element - 要查找的元素
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • lastIndexOf

      public static <T> int lastIndexOf(T[] list, Object element, int start, int end)
      参数:
      list - 数组
      element - 要查找的元素
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • containsRef

      public static <T> boolean containsRef(T[] list, Object element)
      判断是否存在给定元素的引用
    • indexOfRef

      public static <T> int indexOfRef(T[] list, Object element)
      查找对象引用在数组中的索引
    • lastIndexOfRef

      public static <T> int lastIndexOfRef(T[] list, Object element)
      反向查找对象引用在数组中的索引
    • indexOfRef

      public static <T> int indexOfRef(T[] list, Object element, int start, int end)
      参数:
      list - 数组
      element - 要查找的元素
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • lastIndexOfRef

      public static <T> int lastIndexOfRef(T[] list, Object element, int start, int end)
      参数:
      list - 数组
      element - 要查找的元素
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • containsCustom

      public static <T> boolean containsCustom(T[] list, Predicate<? super T> indexFunc)
    • indexOfCustom

      public static <T> int indexOfCustom(T[] list, Predicate<? super T> indexFunc)
    • lastIndexOfCustom

      public static <T> int lastIndexOfCustom(T[] list, Predicate<? super T> indexFunc)
    • indexOfCustom

      public static <T> int indexOfCustom(T[] list, Predicate<? super T> indexFunc, int start, int end)
      参数:
      list - 数组
      indexFunc - 查询函数
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • lastIndexOfCustom

      public static <T> int lastIndexOfCustom(T[] list, Predicate<? super T> indexFunc, int start, int end)
      参数:
      list - 数组
      indexFunc - 查询函数
      start - 数组的有效区间起始下标(inclusive)
      end - 数组的有效区间结束下标(exclusive)
    • swap

      public static void swap(int[] array, int i, int j)
    • swap

      public static void swap(long[] array, int i, int j)
    • swap

      public static void swap(float[] array, int i, int j)
    • swap

      public static void swap(double[] array, int i, int j)
    • swap

      public static void swap(Object[] array, int i, int j)
    • shuffle

      public static void shuffle(int[] array)
    • shuffle

      public static void shuffle(long[] array)
    • shuffle

      public static void shuffle(float[] array)
    • shuffle

      public static void shuffle(double[] array)
    • shuffle

      public static void shuffle(Object[] array)
    • binarySearch

      public static <T> int binarySearch(T[] array, ToIntFunction<? super T> c)
      如果元素存在,则返回元素对应的下标; 如果元素不存在,则返回(-(insertion point) - 1) 即: (index + 1) * -1 可得应当插入的下标。
      参数:
      array - 数组
      c - 比较器
      返回:
      元素下标或插入下标
    • binarySearch

      public static <T> int binarySearch(T[] array, int fromIndex, int toIndex, ToIntFunction<? super T> c)
      如果元素存在,则返回元素对应的下标; 如果元素不存在,则返回(-(insertion point) - 1) 即: (index + 1) * -1 可得应当插入的下标。
      参数:
      array - 数组
      fromIndex - 开始索引
      toIndex - 结束索引
      c - 比较器
      返回:
      元素下标或插入下标
    • asList

      public static <E> List<E> asList(E[] array)
    • asList

      public static <E> List<E> asList(E[] array, int offset, int length)
    • toList

      public static <E> ArrayList<E> toList(E[] array)
    • toList

      public static <E> ArrayList<E> toList(E[] array, int offset, int length)
    • toIntArray

      public static int[] toIntArray(List<Integer> list)
    • toLongArray

      public static long[] toLongArray(List<Long> list)
    • toFloatArray

      public static float[] toFloatArray(List<Float> list)
    • toDoubleArray

      public static double[] toDoubleArray(List<Double> list)
    • arrayRankSymbol

      public static String arrayRankSymbol(int rank)
    • getRootComponentType

      public static Class<?> getRootComponentType(Class<?> clz)
      获取根元素的类型 -- 如果Type是数组,则返回最底层的元素类型;如果不是数组,则返回type
    • getArrayRank

      public static int getArrayRank(Class<?> clz)
      获取数组的阶数 -- 如果不是数组,则返回0