mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
commit
22366f38f1
@ -26,13 +26,14 @@ public class Partition<T> extends AbstractList<List<T>> {
|
||||
*/
|
||||
public Partition(List<T> list, int size) {
|
||||
this.list = list;
|
||||
this.size = Math.min(size, list.size());
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> get(int index) {
|
||||
int start = index * size;
|
||||
int end = Math.min(start + size, list.size());
|
||||
int listSize = list.size();
|
||||
int start = Math.min(index * size, listSize);
|
||||
int end = Math.min(start + size, listSize);
|
||||
return list.subList(start, end);
|
||||
}
|
||||
|
||||
@ -41,10 +42,7 @@ public class Partition<T> extends AbstractList<List<T>> {
|
||||
// 此处采用动态计算,以应对list变
|
||||
final int size = this.size;
|
||||
final int total = list.size();
|
||||
int length = total / size;
|
||||
if(total % size > 0){
|
||||
length += 1;
|
||||
}
|
||||
int length = (total + size - 1) / size;
|
||||
return length;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user