Java HashSet clone() MethodThe clone() method of Java HashSet class is used to return a shallow copy of the specified HashSet. SyntaxFollowing is the declaration of clone() method: ParameterThis method does not accept any parameter. ReturnsThe clone() method returns a shallow copy of this HashSet. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: HashSet elements: [Google, 101, Hindi100, JavaTpoint, Facebook] The new clone set elements: [Google, 101, JavaTpoint, Facebook, Hindi100] Example 2Test it NowOutput: Hash set Elements: [151, 121, 111] The new clone set elements: [121, 151, 111] Example 3Test it NowOutput: Elements of the hset1: DFC SSSIT JTP Elements of the hset2 after clone() operation: DFC SSSIT JTP
Next TopicHashSet contains() Method
|