Hashmap class is a part of java.util package. In hashmap we can store key and value pairs , only with unique keys.If we try to insert a duplicate key it will replace the old value with new value. Many built-in methods are there in hashmap class which makes it easy to perform operations on them, like insertion , deletion and many more. One of those methods is Java Hashmap clone() Method.
To know more about Hashmap clone() Method read the complete article.
Java Hashmap clone() Method
The hashmap clone() method is used to make a copy of the hashmap. This method returns a shallow of the hashmap.
A shallow copy means that the data is not copied but a reference to key and values is copied. Below in this page you can find it’s syntax, return values, parameters with detailed examples.
Syntax :
hashmap.clone();
ParametersThis method does not take any parameter.
What happened above : In the above example a hashmap is created, initially which is empty and elements are inserted in hash_map_1. Now clone() method is used to make a copy of the hashmap and store it in another hashmap.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment