[Java] 纯文本查看 复制代码 /**
* 描述:分割Map
* [url=home.php?mod=space&uid=952169]@Param[/url] map 原始数据
* @param pageSize 每个map数量
* [url=home.php?mod=space&uid=155549]@Return[/url] ListList<Map<K, V>>
*
*/
public static <K, V> List<Map<K, V>> splitMap(Map<K, V> map, int pageSize) {
if (map == null || map.isEmpty()) {
return Collections.emptyList();
}
pageSize = pageSize == 0 ? 10000 : pageSize;
List<Map<K, V>> newList = new ArrayList<>();
int j = 0;
for (K k : map.keySet()) {
if (j % pageSize == 0) {
newList.add(new HashMap<>());
}
newList.get(newList.size() - 1).put(k, map.get(k));
j++;
}
return newList;
}
[Java] 纯文本查看 复制代码 public static <T> Map<Integer, List<T>> splitList(List<T> t, int num) {
Map<Integer, List<T>> subList = new HashMap<>(num);
int num1 = (int) Math.floor(t.size() / num);
for (int i = 0; i < num; i++) {
subList.put(i, t.subList(i * num1, (i + 1) * num1));
if (i == num - 1) {
subList.put(i, t.subList(i * num1, t.size()));
}
}
return subList;
} |