8:45 pm - Sunday September 23, 2018

HashMap Example program for clone()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@AUTHOR:candidjava.com
@DESCRIPTION:cloning the hash elements
 */
import java.util.*;

public class HashClone {
	public static void main(String args[]) {
		HashMap hm = new HashMap(); // creating hash object
		hm.put("sun", "1"); // adding key value pair for hash object
		hm.put("moon", "2");
		hm.put("star", "3");
		System.out.println("actual arraylist:" + hm);
		HashMap copy = (HashMap) hm.clone(); // cloning the hash elements
		System.out.println("Cloned arraylist:" + copy);// displaying the cloned elements
		}
}

OUTPUT:
actual arraylist:{moon=2, star=3, sun=1}
Cloned arraylist:{moon=2, star=3, sun=1}

Filed in: Z-A All Java Codes

Comments are closed.