Java Collection contains() MethodThe contains() method of Java Collection Interface returns a Boolean value 'true', if it contains the specified element in the collection. SyntaxParametersThe parameter 'o' represents the element whose occurrence in this collection is to be tested. 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 contains() method returns Boolean value 'true' if this collection contains all the specified element else it returns false. Example 1Test it NowOutput: Rama is present Example 2Output: Q. Enter smallest even prime no Ans 2 Your answer is correct. Example 3Test it NowOutput: Geeta is present on 12.08.18 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