如何将列表拆分为给定数量的子列表? [英] how to split a list into a given number of sub-lists?

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

问题描述

我有一个列表,可能超过了1000个字符串,但是我不知道确切数量.

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

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

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

例如,如果我有一个1323个成员的列表,如何最好地将其分成3个几乎均匀大小的列表?

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

我已经看到GuavaCommons通过分区功能拆分列表的方式,但是该功能会将列表拆分成给定大小的块,而不是给定数量的组(子列表).

I have seen the Guava and Commons way of splitting lists by the partition function, but that function will split the list into given size of chunks and not given number of groups (sub-lists).

推荐答案

用法:

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

这篇关于如何将列表拆分为给定数量的子列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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