类 ListArrayUtil
- 作者:
- 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/Characterstatic <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) 多个数组合并为一个数组,顺序合并
-
构造器详细资料
-
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
指定类型的列表转换为指定类型数组调用示例:
List < String > list1=new ArrayList<>();
list1.add("1");
list1.add("2");
String[] newArr = ListArrayUtil.listToArray(list1,String.class);
- 参数:
list- 待转换的集合entityClass- 数组的接收类型- 返回:
-
arrayToList
数组转列表调用示例:
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
集合去重 (备注:如果是类对象类型集合去重,需要在类里面重写equals和hashCode方法。否则默认即便两个类对象字段相同,也认为是不重复的对象)调用示例:
List < String > list=new ArrayList<>();
list.add("a");
list.add("a");
list.add("b");
List < String > newlist = ListArrayUtil.distinctList(list);
- 参数:
list- 集合- 返回:
-