Java ArrayList remove() methodThe remove() method of Java ArrayList class removes the first matching object in the ArrayList. Syntax:Parameter:"object":It is the ArrayList element that will be removed if exist. Return:Return "true": If this list contained the specified object. Example 1Test it NowOutput: [A, B, C, D, E] true [A, B, D, E] Example 2Test it NowOutput: [Parrot, Owl, Swallow] false [Parrot, Owl, Swallow] Java ArrayList remove(int index) methodThe remove (int index) method of Java ArrayListclass removes an element of specified index of the ArrayList. Syntax:Parameter:"index": index of the element that will be removed. Return:Return "E": the element that was removed from the list. Example 3Test it NowOutput: [] Example 4Test it NowOutput: [1] Example 5Test it NowOutput: throwsIndexOutOfBoundsException Next TopicJava ArrayList |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India