Javatpoint Logo
Javatpoint Logo

Java HashSet clone() Method

The clone() method of Java HashSet class is used to return a shallow copy of the specified HashSet.

Syntax

Following is the declaration of clone() method:

Parameter

This method does not accept any parameter.

Returns

The clone() method returns a shallow copy of this HashSet.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

HashSet elements: [Google, 101, Hindi100, JavaTpoint, Facebook]
The new clone set elements: [Google, 101, JavaTpoint, Facebook, Hindi100]

Example 2

Test it Now

Output:

Hash set Elements: [151, 121, 111]
The new clone set elements: [121, 151, 111]

Example 3

Test it Now

Output:

Elements of the hset1:
DFC
SSSIT
JTP
Elements of the hset2 after clone() operation:
DFC
SSSIT
JTP






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA