ArrayList.removeRange()

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


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer