From a425ac5fb3accbd2eec1f7ef6f506433f1f9bc4f Mon Sep 17 00:00:00 2001 From: Boyi C Date: Tue, 12 Jul 2022 17:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20Partition=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/core/collection/Partition.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/Partition.java b/hutool-core/src/main/java/cn/hutool/core/collection/Partition.java index fa555b974..364af5c53 100644 --- a/hutool-core/src/main/java/cn/hutool/core/collection/Partition.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/Partition.java @@ -26,13 +26,14 @@ public class Partition extends AbstractList> { */ public Partition(List list, int size) { this.list = list; - this.size = Math.min(size, list.size()); + this.size = size; } @Override public List 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 extends AbstractList> { // 此处采用动态计算,以应对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; }