Java - 将字符串列表拆分成较小的列表? [重复]

时间:2021-07-22 15:52:17

This question already has an answer here:

这个问题在这里已有答案:

I have a list that may be over 1000 strings, however I do not know how many exactly.

我有一个可能超过1000个字符串的列表,但我不知道究竟有多少个。

What is the best way to reduce this list into smaller lists without loosing any members of the list?

在不丢失列表中任何成员的情况下,将此列表缩减为较小列表的最佳方法是什么?

For example If I have a list of 1323 members, how can I best split it into 3 almost evenly sized lists?

例如,如果我有一个1323名成员的列表,我怎样才能最好地将它分成3个几乎同等大小的列表?

I have seen the Guava and Commons way of splitting lists, but not sure which one is best in this case.

我已经看到了Guava和Commons分割列表的方式,但不确定在这种情况下哪一个最好。

1 个解决方案

#1


2  

Guava has a function Lists.partition which will do this for you

Guava有一个Lists.partition函数,可以为你做这个

Usage:

Lists.partition(mylist, mylist.size()/3);

#1


2  

Guava has a function Lists.partition which will do this for you

Guava有一个Lists.partition函数,可以为你做这个

Usage:

Lists.partition(mylist, mylist.size()/3);