I have to divide a list of string in chunks ,hence I have written this method ,
public static List<List<String>> chunkIds(List<String> ids, int max) { List<List<String>> chunks = new ArrayList<>(); for (int i = 0; i < ids.size(); i = i + max) { List<String> chunk = ids.subList(i, i + max); chunks.add(chunk); } return chunks; } when I call the method I get IndexOutOfBoundsException on getting the subList .where max is a chunk size .Could someone please help me understand the index logic wrong here.
idslist andmaxis 3. Then when you get toi=4, you're trying to get items 4 through 7. But the list only has items 0 through 5.