版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
注意:配合ExcelHelper帮助类使用
import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; public class ListHelper { /** * 判断excel是否重复数据 是true 否false * * @param excelFileName * @param args * @return */ public static boolean isExcelRepeat(String excelFileName, int... args) { try { ArrayList<ArrayList<String>> arr = ExcelHelper.getExcel(excelFileName, args); int oldRow = arr.size(); int newRow = removeRepeatLow(arr).size(); // int newRow1 = removeRepeatHeight(arr).size(); if (oldRow != newRow) { return true; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } /** * 去除重复数据低版本jdk * * @param list * @return */ public static ArrayList<ArrayList<String>> removeRepeatLow(ArrayList<ArrayList<String>> list) { HashSet hs = new HashSet(list); list.clear(); list.addAll(hs); return list; } /** * 去除重复数据高版本jdk * * @param list * @return */ public static ArrayList<ArrayList<String>> removeRepeatHeight(ArrayList<ArrayList<String>> list) { ArrayList<ArrayList<String>> arr = (ArrayList<ArrayList<String>>) list.stream().distinct() .collect(Collectors.toList()); return arr; } /** * list分页 * * @param list * @param pageSize * @return */ public static <T> List<List<T>> splitList(List<T> list, int pageSize) { int listSize = list.size(); int page = (listSize + (pageSize - 1)) / pageSize; List<List<T>> listArray = new ArrayList<List<T>>(); for (int i = 0; i < page; i++) { List<T> subList = new ArrayList<T>(); for (int j = 0; j < listSize; j++) { int pageIndex = ((j + 1) + (pageSize - 1)) / pageSize; if (pageIndex == (i + 1)) { subList.add(list.get(j)); } if ((j + 1) == ((j + 1) * pageSize)) { break; } } listArray.add(subList); } return listArray; } /** * list1.addAll(list2); //并集 * * list2.removeAll(list1);list1.addAll(list2); //去重复并集 * * list1.retainAll(list2); //交集 * * list1.removeAll(list2); //差集 */ }
原文链接:https://www.idaobin.com/archives/2058.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告