Home Tutorial Java Collections Arraylist Java ArrayList removerange

 
 

Share on Google+Share on Google+
Java ArrayList removerange
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This section demonstrates how to use the removeRange() method

  • removeRange() is a protected method of the Java ArrayList.
  • It removes elements  from the given list present in the given range.
  • As it is a protected method, so it cannot be directly used.
  • A class has to extend it then it can be used.


Java Arraylist Remove range Example
import java.util.*;

public class List1 extends ArrayList{

public static void main(String[] args) {
String  ar[]={"india","pakistan","United Kingdom","Japan"};
List1 list=new List1();
list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);
System.out.println(list);
list.removeRange(0,2);
System.out.println(list);
}
}
Output
[india, pakistan, United Kingdom, Japan]
[United Kingdom, Japan]

Advertisement

Related Tags for Java ArrayList removerange:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com