Java HashSet contains() MethodThe contains() method of Java HashSet class is used to check if this HashSet contains the specified element or not. It returns true if element is found otherwise, returns false. SyntaxFollowing is the declaration of contains() method: Parameter
ReturnsThe contains() method returns true if this set contains the specified element. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Output: Hash set Elements: [21, 151, 11, 110, 15] Does the Set contains '110'? :- true Does the Set contains '555'? :- false Example 2Output: Enter student name: Rishi Rishi found on student list. Example 3Output: Elements of the HashSet: Twitter Instagram Facebook Does the HashSet contains 'Whatsapp'? :- false Does the HashSet contains 'Facebook'? :- true Next TopicJava hashset isempty method |
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