HashMap clone
In this chapter you will learn:
Clone a HashMap
clone()
creates a copy of the HashMap
import java.util.HashMap;
//from j av a 2 s . c o m
public class Main {
public static void main(String[] a) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
HashMap map2 = (HashMap)map.clone();
System.out.println(map2);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections