3:28 pm - Sunday June 25, 2017

Hashtable 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

// Hashtable Example program for clone()
/**
@author: candidjava.com
@description: This program gives the copy of the existing Hashtable.
*/
import java.util.*;
public class Clone {
public static void main(String[] args) {
Hashtable h1 = new Hashtable(); // Creating ne Hashtable
// Adding elements to the Hashtable
h1.put(5, "Five");
h1.put('N', "new");
h1.put("sachin", "cricket");
System.out.println("Hashtable Elements are:  " + h1);
Hashtable h2 = new Hashtable(); // Creating another Hashtable
h2 = (Hashtable) h1.clone(); // copying the contents of h1 to h2
System.out.println("New Hashtable values are:  " + h2);
}
}

Output:
Hashtable Elements are    :  {5=Five, sachin=cricket, N=new}
New Hashtable values are :  {5=Five, sachin=cricket, N=new}

BACK

Filed in: Z-A All Java Codes

Comments are closed.