How to Split an ArrayList in Multiple Small ArrayLists? Last Updated : 01 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, ArrayList is a pre-defined class of the Java collection framework, and it can be used to add the elements dynamically. One more special feature is that it can shrink the size dynamically to add or remove the elements from the ArrayList. In this article, we will discuss how to split an ArrayList into multiple small ArrayLists. Step-by-Step ImplementationCreate a String ArrayList named as mainList.Add the values into the mainList ArrayList.Define the subList size and write another method named splitArrayList with two parameters ArrayList, and SubList size.The splitArrayList method accepts two parameters ArrayList and subList size and it can convert the ArrayList into subList based on the size of the subList size.Print the sub ArrayList.Program to split an ArrayList in multiple small ArrayLists in Java Java // Java Program to split an ArrayList in multiple small ArrayLists import java.util.ArrayList; import java.util.List; public class GFGSplitArrayList { //main method public static void main(String[] args) { //create the mainList ArrayList ArrayList<String> mainList = new ArrayList<>(); // Adding values into ArrayList of Strings mainList.add("C"); mainList.add("Java"); mainList.add("Python"); mainList.add("HTML"); mainList.add("CSS"); mainList.add("Six"); mainList.add("Spring"); mainList.add("Hibernate"); mainList.add("NodeJs"); // Split the ArrayList into smaller ArrayLists with size 3 int subListSize = 3; List<ArrayList<String>> subLists = splitArrayList(mainList, subListSize); // print the result for (int i = 0; i < subLists.size(); i++) { System.out.println("Sublist " + (i + 1) + ": " + subLists.get(i)); } } // Method to split an ArrayList into smaller ArrayLists private static <T> List<ArrayList<T>> splitArrayList(ArrayList<T> original, int size) { List<ArrayList<T>> subLists = new ArrayList<>(); for (int i = 0; i < original.size(); i += size) { int end = Math.min(i + size, original.size()); subLists.add(new ArrayList<>(original.subList(i, end))); } return subLists; } } OutputSublist 1: [C, Java, Python] Sublist 2: [HTML, CSS, Six] Sublist 3: [Spring, Hibernate, NodeJs] Explanation of the above Program:In above example, we convert the ArrayList split into the 3 sub ArrayList with the size of 3 in sub ArrayList. First define the main ArrayList names as mainList and added the values into the mainList. After that define the size of sub ArrayList then iterate the main ArrayList adding the values into the subList of the program. Comment More infoAdvertise with us Next Article How to Split an ArrayList in Multiple Small ArrayLists? K kadambalamatclo Follow Improve Article Tags : Java Java Programs Java-ArrayList Java Examples Practice Tags : Java Similar Reads How to Swap Two Elements in an ArrayList in Java? We can swap two elements of Array List using Collections.swap() method. This method accepts three arguments. The first argument is the ArrayList and the other two arguments are the indices of the elements. This method returns nothing. Syntax: public static void swap(List list, int a, int b); Parame 2 min read How to clone an ArrayList to another ArrayList in Java? The clone() method of the ArrayList class is used to clone an ArrayList to another ArrayList in Java as it returns a shallow copy of its caller ArrayList. Syntax: public Object clone(); Return Value: This function returns a copy of the instance of Object. Below program illustrate the Java.util.Arra 2 min read How to Convert a String to ArrayList in Java? Converting String to ArrayList means each character of the string is added as a separator character element in the ArrayList. Example: Input: 0001 Output: 0 0 0 1 Input: Geeks Output: G e e k s We can easily convert String to ArrayList in Java using the split() method and regular expression. Paramet 1 min read Split a Vector into Multiple Smaller Vectors in Java In the realm of Java programming, the manipulation of vectors is a common task. One particularly useful operation is splitting a vector into multiple smaller vectors. This article aims to provide a detailed guide on achieving this in Java, catering to both beginners and experienced developers. Prere 3 min read How to Increase the capacity (size) of ArrayList? ArrayList class is a resizable array, present in java.util package. The difference between an array and an ArrayList in Java, is that the size of an array cannot be modified (i.e. if you want to append/add or remove element(s) to/from an array, you have to create a new array. However, elements can b 2 min read Like