What does the method removeRange(int fromIndex, int toIndex) do in java?


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: 20-Feb-2020

64 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements