如何将数组列表分成相等的部分? [英] How to split array list into equal parts?

查看:31
本文介绍了如何将数组列表分成相等的部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在运行之前不知道它的大小的情况下将 ArrayList 分成不同的部分?我知道有一种方法叫做:

Is there anyway to split ArrayList into different parts without knowing size of it until runtime? I know there is a method called:

list.subList(a,b);

但我们需要明确提及列表的起始和结束范围.我的问题是,我们得到一个包含帐号的数组列表,其中包含 2000,4000 个帐号之类的数据(在编码期间不会知道这些数字),我需要将此帐号传递到 PL/SQL 的 IN 查询中,如IN 中不支持超过 1000 个值,我正在尝试将其拆分为多个块并将其发送到查询

but we need to explicitly mention staring and ending range of list. My problem is, we get a arraylist containing account numbers which is having data like 2000,4000 account numbers (there numbers will not be known during coding time), and I need to pass this acc nos into IN query of PL/SQL, as IN doesn't support more than 1000 values in it, I am trying to split into multiple chunks and sending it to query

注意:我不能使用任何外部库,如 Guava 等.:(感谢您提供这方面的任何指导.

Note: I cannot use any external libraries like Guava etc.. :( Any guide in this regard is appreciated.

推荐答案

这应该给你所有的部分:

This should give you all your parts :

int partitionSize = 1000;
List<List<Integer>> partitions = new LinkedList<List<Integer>>();
for (int i = 0; i < originalList.size(); i += partitionSize) {
    partitions.add(originalList.subList(i,
            Math.min(i + partitionSize, originalList.size())));
}

这篇关于如何将数组列表分成相等的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆