Java HashSet add() MethodThe add() is a method of Java HashSet class which adds the specified element to this set if this set contains no element. If it is already contain the element, the call leaves the set unchanged and returns false. SyntaxFollowing is the declaration of add() method: Parameter
ReturnsThe add() method returns true if this set did not already contain the specified element. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Vijay Ravi Ajay Example 2Test it NowOutput: Hash set Elements: [151, 121, 111] Example 3Test it NowOutput: Is the insertion successful?? - true Elements of the HashSet: Google Twitter Instagram Facebook Example 4Test it NowOutput: 103 Operating System Galvin Wiley 6 102 Data Communications & Networking Forouzan Mc Graw Hill 4 101 Let us C Yashwant Kanetkar BPB 8
Next TopicHashSet clear() Method
|