12:51 am - Thursday July 27, 2017

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

                                 This tutorial explains how to Create a copy of treemap using Object clone() method.It will make copy of the whole key and values.

Example


import java.util.TreeMap;

public class  TreeMapClone

{

public static void main(String a[])

{

   TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

   treemap.put(2, "two");

   treemap.put(1, "one");

   treemap.put(3, "three");

   treemap.put(6, "six");

   treemap.put(5, "five");

   System.out.println("Cloning tree map");

   System.out.println("Original map: "+ treemap);

   System.out.println("Cloned map: "+ treemap.clone());

 }

}

Output

               Cloning tree map

               Original map: {1=one, 2=two, 3=three, 5=five, 6=six}

              Cloned map: {1=one, 2=two, 3=three, 5=five, 6=six}

BACK

Filed in: Java Examples

Comments are closed.