ArrayList.removeRange()
Java ArrayList()
ArrayList.removeRange(int startIndex, int endIndex) remove the elements over a range by using postions
startIndex ( integer ) , Starting position of the range of element to be removed.
endIndex ( integer ) , Ending position of the range before which the elements are to be removed.
Returns : No remturn value for this.
Examples with output
« add()
ArrayList<String> languages = new ArrayList<String>();
languages.add("Zero");
languages.add("One");
languages.add("Two");
languages.add("Three");
languages.add("Four");
languages.add("Five");
System.out.println(languages); //[Zero, One, Two, Three, Four, Five]
languages.removeRange(1,3);
System.out.println(languages); //[Zero, Three, Four, Five]
Note : removeRange is not part of public API so we may have to use this line. This line behind calls removeRange() and remove the reange of elements.
languages.subList(1,3).clear();
After removal the postion of elements shifted to left.
Note : in the range we have given, the startIndex is inclusive but endIndex is not inclusive.
« ArrayList Tutorials
« Java
This article is written by plus2net.com team.
Be the first to post comment:
plus2net.com