类 ListArrayUtil

java.lang.Object
com.mbap.util.lang.ListArrayUtil

public class ListArrayUtil extends Object
处理列表、数组相关工具类,包括列表数组互转,数组合并、去重、排序等等
作者:
Amanda.Z
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static double[]
    arrAsc(double[] arr)
    对数组升序排序
    static float[]
    arrAsc(float[] arr)
    对数组升序排序
    static int[]
    arrAsc(int[] arr)
    对数组升序排序
    static long[]
    arrAsc(long[] arr)
    对数组升序排序
    static <T> List<T>
    arrayToList(T[] arr)
    数组转列表
    static double[]
    arrDesc(double[] arr)
    对数组降序排序
    static float[]
    arrDesc(float[] arr)
    对数组降序排序
    static int[]
    arrDesc(int[] arr)
    对数组降序排序
    static long[]
    arrDesc(long[] arr)
    对数组降序排序
    static char[]
    distinctArray(char[] arr)
    char型的数组去重
    static double[]
    distinctArray(double[] arr)
    double型的数组去重
    static float[]
    distinctArray(float[] arr)
    float型的数组去重
    static int[]
    distinctArray(int[] arr)
    整型的数组去重
    static <T> T[]
    distinctArray(T[] arr)
    对象类型的数组去重,适用于String/Integer/Double/Float/Long/Character
    static <T> List<T>
    distinctList(List<T> list)
    集合去重 (备注:如果是类对象类型集合去重,需要在类里面重写equals和hashCode方法。否则默认即便两个类对象字段相同,也认为是不重复的对象)
    static <T> T[]
    listToArray(List<T> list, Class<T> entityClass)
    指定类型的列表转换为指定类型数组
    static <T> T[]
    merge(T[] first, T[]... rest)
    多个数组合并为一个数组,顺序合并

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ListArrayUtil

      public ListArrayUtil()
  • 方法详细资料

    • merge

      public static <T> T[] merge(T[] first, T[]... rest)
      多个数组合并为一个数组,顺序合并

      调用示例:

      String [] arr1=new String[]{"1","2"};

      String [] arr2=new String[]{"3","4"};

      String[] r1=ListArrayUtil.merge(arr1, arr2);

      调用示例:

      Integer [] arr11=new Integer[]{1,2};

      Integer [] arr22=new Integer[]{3,4};

      Integer[] r2=ListArrayUtil.merge(arr11, arr22);

      注意本方法不支持基础数据类型的数组合并,如int数组,仅支持对象类型的数组,如String数组、Integer数组等其他对象类型数组

      参数:
      first - 第一个数组
      rest - 可变参数,剩余的数组
      返回:
    • listToArray

      public static <T> T[] listToArray(List<T> list, Class<T> entityClass)
      指定类型的列表转换为指定类型数组

      调用示例:

      List < String > list1=new ArrayList<>();

      list1.add("1");

      list1.add("2");

      String[] newArr = ListArrayUtil.listToArray(list1,String.class);

      参数:
      list - 待转换的集合
      entityClass - 数组的接收类型
      返回:
    • arrayToList

      public static <T> List<T> arrayToList(T[] arr)
      数组转列表

      调用示例:

      String[] array = new String[]{"a","b","c"};

      List list = ListArrayUtil.arrayToList(array);

      参数:
      arr - 待转换数组
      返回:
    • arrDesc

      public static int[] arrDesc(int[] arr)
      对数组降序排序
      参数:
      arr - 数组
      返回:
    • arrDesc

      public static long[] arrDesc(long[] arr)
      对数组降序排序
      参数:
      arr - 数组
      返回:
    • arrDesc

      public static float[] arrDesc(float[] arr)
      对数组降序排序
      参数:
      arr - 数组
      返回:
    • arrDesc

      public static double[] arrDesc(double[] arr)
      对数组降序排序
      参数:
      arr - 数组
      返回:
    • arrAsc

      public static int[] arrAsc(int[] arr)
      对数组升序排序
      参数:
      arr - 数组
      返回:
    • arrAsc

      public static long[] arrAsc(long[] arr)
      对数组升序排序
      参数:
      arr - 数组
      返回:
    • arrAsc

      public static float[] arrAsc(float[] arr)
      对数组升序排序
      参数:
      arr - 数组
      返回:
    • arrAsc

      public static double[] arrAsc(double[] arr)
      对数组升序排序
      参数:
      arr - 数组
      返回:
    • distinctArray

      public static <T> T[] distinctArray(T[] arr)
      对象类型的数组去重,适用于String/Integer/Double/Float/Long/Character

      调用示例:

      Integer[] array = new Integer[]{1,2,3,4,2,2,1};

      Integer[] newarr = ListArrayUtil.distinctArray(array);

      参数:
      arr -
      返回:
    • distinctArray

      public static int[] distinctArray(int[] arr)
      整型的数组去重

      调用示例:

      int[] array = {1,2,3,4,2,2,1};

      int[] newarr = ListArrayUtil.distinctArray(array);

      参数:
      arr -
      返回:
    • distinctArray

      public static float[] distinctArray(float[] arr)
      float型的数组去重

      调用示例:

      float[] array ={1.1f,1.2f,1.1f,1.3f};

      float[] newarr = ListArrayUtil.distinctArray(array);

      参数:
      arr -
      返回:
    • distinctArray

      public static double[] distinctArray(double[] arr)
      double型的数组去重

      调用示例:

      double[] array ={1.1d,1.2d,1.1d,1.3d};

      double[] newarr = ListArrayUtil.distinctArray(array);

      参数:
      arr -
      返回:
    • distinctArray

      public static char[] distinctArray(char[] arr)
      char型的数组去重

      调用示例:

      char[] array ={'a','a','b','b'};

      char[] newarr = ListArrayUtil.distinctArray(array);

      参数:
      arr -
      返回:
    • distinctList

      public static <T> List<T> distinctList(List<T> list)
      集合去重 (备注:如果是类对象类型集合去重,需要在类里面重写equals和hashCode方法。否则默认即便两个类对象字段相同,也认为是不重复的对象)

      调用示例:

      List < String > list=new ArrayList<>();

      list.add("a");

      list.add("a");

      list.add("b");

      List < String > newlist = ListArrayUtil.distinctList(list);

      参数:
      list - 集合
      返回: