protected
void removeRange(int fromIndex, int toIndex)
Removes
from this list all of the elements whose index is between fromIndex,
inclusive, and toIndex, exclusive. Methods equals, hashCode,
listIterator, removeRange, subList are inherited from AbstractList.
import java.util.*; class LinkedListRemoveRange<Integer> extends LinkedList<Integer>{ public static void main(String args[]){ LinkedListRemoveRange myList = new LinkedListRemoveRange(); /* Add Elements to myList */ myList.add(10); myList.add(20); myList.add(30); myList.add(40); myList.add(50); System.out.println("Elements in myList are"); System.out.println(myList); System.out.println("Removing elements from index 1 to 3"); myList.removeRange(1,4); System.out.println("Elements in myList are"); System.out.println(myList); } }
Output
Elements in myList are [10, 20, 30, 40, 50] Removing elements from index 1 to 3 Elements in myList are [10, 50]
No comments:
Post a Comment