Java Collection remove() MethodThe remove() method of Java Collection Interface is used to remove a single instance of the specified element from this collection. SyntaxParametersThe parameter 'o' represents the element to be removed from this collection if it is present. ThrowsClassCastException- if the type of the specified element is not compatible with this collection NullPointerException- if the specified element is null and this collection does not allow null elements ReturnsThe remove() method returns a boolean value 'true' if the specified element is successfully removed as a result of this call. Example 1Test it NowOutput: 52 532 5 15 After removing 52 Collection : [532, 5, 15] Example 2Test it NowOutput: Reema Geetanajli Mahesh Ajeet remove method will return : false Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.ArrayDeque.addLast(ArrayDeque.java:249) at java.util.ArrayDeque.add(ArrayDeque.java:423) at com.javaTpoint.JavaCollectionRemoveExample3.main(JavaCollectionRemoveExample3.java:13) Next TopicJava-Collection |
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