Wednesday, 4 March 2015

Java : Collection Framework : Hashtable (Clone)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=fsuYAb5-F1c&list=UUhwKlOVR041tngjerWxVccw

HashtableExample.java
import java.util.Hashtable;

/*
 * Example of clone() method.
 */
public class HashtableExample
{
    public static void main( String[] args )
    {

        Hashtable<String, String> hashtable = new Hashtable<String, String>();

        /*
         * Key = CountryCode,Value = CountryName
         */
        hashtable.put("AF", "AFGHANISTAN");
        hashtable.put("BE", "BELGIUM");
        hashtable.put("US", "UNITED STATES");
        hashtable.put("IN", "INDIA");
        
        System.out.println("hashtable : " + hashtable + "\n");
        
        /*
         * Creates a shallow copy of this hashtable. All the structure of the
         * hashtable itself is copied, but the keys and values are not cloned.
         * This is a relatively expensive operation.
         */
        Object object = hashtable.clone();

        System.out
                .println("Object class name : " + object.getClass().getName() +  "\n");

        Hashtable<String, String> clonedHashtable = (Hashtable<String, String>) object;

        System.out.println("Cloned Hashtable : " + clonedHashtable);

    }
}
Output
hashtable : {IN=INDIA, AF=AFGHANISTAN, BE=BELGIUM, US=UNITED STATES}

Object class name : java.util.Hashtable

Cloned Hashtable : {IN=INDIA, AF=AFGHANISTAN, BE=BELGIUM, US=UNITED STATES}
To Download HashtableDemoClone Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoClone.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge