Java: split a List into two sub-Lists?

后端 未结 14 1561
执笔经年
执笔经年 2020-12-08 02:29

What\'s the simplest, most standard, and/or most efficient way to split a List into two sub-Lists in Java? It\'s OK to mutate the original List, so no copying should be nece

14条回答
  •  渐次进展
    2020-12-08 03:04

    //Here is my list
        ArrayList items=new ArrayList();
        Integer startIndex = 0;
                int j = 0;
                for (; j < items.size() - 1; j++) {//always start with next index not again 0
                    for (int i = 0; i < 4; i++) { // divide into equal part with 4 item
                        startIndex = startIndex + 1;
                        j = startIndex;
                    }
                }
    

提交回复
热议问题