As-Is ํ๋ค๊ฒ ๋๋๋ ๋ฒ (subList)
public static void main(String[] args) {
List<Integer> integerList = new ArrayList<>();
for(int i = 0; i<10000; i++) {
integerList.add(i);
}
int size = integerList.size();
int page = size / 100 + 1;
for (int i = 0; i < page; i++) {
int startIndex = i * 100;
int endIndex = i == page - 1 ? size : (i + 1) * 100;
List<Integer> subList = integerList.subList(startIndex, endIndex);
}
}
- List<E> subList(int fromIndex, int toIndex); ์ฌ์ฉ
- ๋ฉ๋ชจ๋ฆฌ ์ด์๋, ๋ถ๋ชจList๊ฐ ๋ฐ๋์ ๋ฐ๋ผ SubList๊ฐ ์ํฅ์ ๋ฐ์ Exception์ ๋ฑ์ ์ ์๊ธฐ ๋๋ฌธ์ newArrayList<>(integerList.subList(startIndex, endIndex)); // ์๋ก ์์ฑํ๋ ๊ฒ์ ๊ถ์ฅ
To-Be ๊ฐ๋จํ๊ฒ ๋๋๋ ๋ฒ : Guava Library ์ฌ์ฉ (Lists.partition)
public static void main(String[] args) {
List<Integer> integerList = new ArrayList<>();
for(int i = 0; i<10000; i++) {
integerList.add(i);
}
List<List<Integer>> lists = Lists.partition(integerList, 100);
}
'๊ฐ๋ฐ์ํ > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
char to int (0) | 2023.05.10 |
---|---|
ObjectMapper ์ฌ์ฉ List Mapping (0) | 2022.11.28 |
[Java] Null String Casting (0) | 2022.04.29 |
[Java] Map ์ ๊ณต ๋ฉ์๋๋ค ์ ๋ฆฌ (0) | 2022.04.26 |
[JAVA] String ์ค๋ณต์ ๊ฑฐ Stream (0) | 2022.03.22 |