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

Java 8Object Oriented ProgrammingProgramming

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]
raja
Published on 16-Jan-2018 09:57:19
Advertisements