• java集合分割


    java集合分割成等份的小集合:

     private <T> List<List<T>> getSubList(List list,int len) {
            if(list.size()<len){
                return list;
            }
            List<List<T>> listGroup = new ArrayList<List<T>>();
            int listSize = list.size();
            //子集合的长度
            int toIndex = len;
            for (int i = 0; i < list.size(); i += len) {
                if (i + len > listSize) {
                    toIndex = listSize - i;
                }
                List<T> newList = list.subList(i, i + toIndex);
                listGroup.add(newList);
            }
            return listGroup;
        }

    eg:

        /**
         * @return
         * @Author
         * @Description //TODO 集合分割
         * @Date 2019/1/24 16:48
         * @Param
         */
        private List<List<PushResult>> getSubList(List list, int len) {
            List<List<PushResult>> listGroup = new ArrayList<List<PushResult>>();
            if (list.size() < len) {
                listGroup.add(list);
                return listGroup;
            }
    
            int listSize = list.size();
            //子集合的长度
            int toIndex = len;
            for (int i = 0; i < list.size(); i += len) {
                if (i + len > listSize) {
                    toIndex = listSize - i;
                }
                List<PushResult> newList = list.subList(i, i + toIndex);
                listGroup.add(newList);
            }
            return listGroup;
        }
  • 相关阅读:
    移动web基础
    CSS3
    HTML5新属性
    CSS3初体验之伪元素选择器
    HTML5+CSS3day_01
    CSS补充
    CSS_day02
    CSS_day01
    HTML_day02
    HTML_day01
  • 原文地址:https://www.cnblogs.com/dw3306/p/10154105.html
Copyright © 2020-2023  润新知