How to remove a SubList from a List in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Given a list in Java, the task is to remove all the elements in the sublist whose index is between fromIndex, inclusive, and toIndex, exclusive. The range of the index is defined by the user. Example: Input list = [1, 2, 3, 4, 5, 6, 7, 8], fromIndex = 2, endIndex = 4 Output [1, 2, 5, 6, 7, 8] Input list = ['G', 'E', 'E', 'G', 'G', 'K', 'S'], fromIndex = 3, endIndex = 5 Output ['G', 'E', 'E', 'K', 'S'] Method 1: Using subList() and clear() method Syntax: List.subList(int fromIndex, int toIndex).clear() Example: Java // Java code to remove a subList using // subList(a, b).clear() method import java.util.*; public class AbstractListDemo { public static void main(String args[]) { // Creating an empty AbstractList AbstractList<String> list = new LinkedList<String>(); // Using add() method // to add elements in the list list.add("GFG"); list.add("for"); list.add("Geeks"); list.add("computer"); list.add("portal"); // Output the list System.out.println("Original List: " + list); // subList and clear method // to remove elements // specified in the range list.subList(1, 3).clear(); // Print the final list System.out.println("Final List: " + list); } } Output: Original List: [GFG, for, Geeks, computer, portal] Final List: [GFG, computer, portal] Note: Classes which can inherit AbstractList: ArrayList Vector LinkedList Stack Method 2: Using removeRange() method Syntax: List.removeRange(int fromIndex, int toIndex) Example: Java // Java code to remove a subList // using removeRange() method import java.util.*; // since removeRange() is a protected method // ArrayList has to be extend the class public class GFG extends ArrayList<Integer> { public static void main(String[] args) { // create an empty array list GFG arr = new GFG(); // use add() method // to add values in the list arr.add(1); arr.add(2); arr.add(3); arr.add(4); arr.add(5); arr.add(6); arr.add(7); arr.add(8); // prints the list before removing System.out.println("Original List: " + arr); // removing elements in the list // from index 2 to 4 arr.removeRange(2, 4); System.out.println("Final List: " + arr); } } Output: Original List: [1, 2, 3, 4, 5, 6, 7, 8] Final List: [1, 2, 5, 6, 7, 8] Create Quiz Comment P ProgrammerAnvesh Follow 2 Improve P ProgrammerAnvesh Follow 2 Improve Article Tags : Java java-list Java-List-Programs Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like