removeRange Method in Java: Explanation and Usage



The removeRange() method of the ArrayList class removes all of the elements from this List whose index is between fromIndex and toIndex.

Example

import java.util.*;

public class ArrayListDemo extends ArrayList{
   public static void main(String[] args) {
      ArrayListDemo arrlist = new ArrayListDemo();
      arrlist.add(10);
      arrlist.add(12);
      arrlist.add(31);
      System.out.println("The list:" + arrlist);
      arrlist.removeRange(0,2);
      System.out.println("The list after using removeRange:" + arrlist);
   }
}

Output

The list:[10, 12, 31]
The list after using removeRange:[31]
Updated on: 2020-02-20T12:24:27+05:30

102 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements