3:34 pm - Sunday June 25, 2017

Create a copy of LinkedHashMap Object 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

BACK

                                 The method public Object clone () displays the copy of the elements present in the linkedhashmap.The cloned Map looks same as that of the actual map.The elements themselves are not cloned.

Example Program


import java.util.LinkedHashMap;

public class LinkedHashMapClone 

{

	public static void main(String args[])

	{

		LinkedHashMap lhm = new LinkedHashMap();

		lhm.put(1, "Add");

		lhm.put(2, "Sub");

		lhm.put(3, "Mul");

		lhm.clone();

		LinkedHashMap lhmm = new LinkedHashMap();

		lhmm = (LinkedHashMap) lhm.clone();

		System.out.println("The LinkedHashMap is:" + lhm);

		System.out.println("The cloned Map is:" + lhmm);

	}

}

Output

    The LinkedHashMap is:{1=Add, 2=Sub, 3=Mul}

    The cloned Map is:{1=Add, 2=Sub, 3=Mul}

 

BACK

Filed in: Java Examples

Comments are closed.