Java Vector retainAll() MethodThe retainAll() method of Java Vector class is used to retain only that elements in the vector which are contained in the specified collection. In other words, it removes all elements from this vector that are not contained in the specified collection. SyntaxFollowing is the declaration of retainAll() method: Parameter
ReturnThe retainAll() method returns true if the vector changed as a result of the call. ExceptionsNullPointerException- This method has thrown an exception if the vector contains one or more null elements and the specified collection does not support null elements or if the specified collection is null. Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Values in vector :[1, 2, 3, 4, 2] Values in vector :[2, 3, 2] Example 2Test it NowOutput: Vector: [A, B, C, 10, 20] Collection retained Final Vector: [A, B, C] Next TopicJava Vector |
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