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 1Test it NowOutput: Hash set Elements: [21, 151, 11, 110, 15] Does the Set contains '110'? :- true Does the Set contains '555'? :- false Example 2Test it NowOutput: Enter student name: Rishi Rishi found on student list. Example 3Test it NowOutput: Elements of the HashSet: Twitter Instagram Facebook Does the HashSet contains 'Whatsapp'? :- false Does the HashSet contains 'Facebook'? :- true
Next TopicHashSet isEmpty() Method
|