TreeMap clone() Method in Java
The java.util.TreeMap.clone() method is used to return a shallow copy of the mentioned treemap. It just creates a copy of the map.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Parameters: The method does not take any parameters.
Return Value: The method just returns a copy of the TreeMap.
Below programs are used to illustrate the working of java.util.TreeMap.clone() Method:
Program 1: Mapping String Values to Integer Keys.
Program 2: Mapping Integer Values to String Keys.
Note: The same operation can be performed with any type of Mappings with variation and combination of different data types.