Hashtable clone() in Java

clone(): This method is available in java.util.Hashtable class of Java.

Syntax:

Object java.util.Hashtable.clone()

This method creates a shallow copy of this hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned.

Parameters: NA

Returns: a clone of the hashtable.

Exceptions: NA

Approach

Java

import java.util.Hashtable;

public class Hashtableclone {
    public static void main(String[] args) {
        Hashtable<String, Integer> hashtable =
new Hashtable<String, Integer>();

        hashtable.put("Hello", 1);
        hashtable.put("World", 2);

        System.out.println(hashtable.clone());
    }
}

Output:

{World=2, Hello=1}


No comments:

Post a Comment