Object clone() Example Program
By candid | Posted :
Jun 24, 2015
| Updated :
Jun 24, 2015
Returns a shallow copy of this LinkedList. (The elements themselves are not cloned.)
Program
package com.candidjava;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.clone() method returns a shallow copy
* of this LinkedList.
*/
public class LinkedListClone {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("kamal");
System.out.println("LinkedList:" + list);
LinkedList list2 = new LinkedList();
list2 = (LinkedList) list.clone();
System.out.println("LinkedList 2:" + list2);
}
}
Output
LinkedList:[anandh, hari, vinoth, kamal]
LinkedList 2:[anandh, hari, vinoth, kamal]
Explanation
public Object clone()
Returns a shallow copy of this LinkedList. (The elements themselves are not cloned.)
Overrides:
clone in class Object
Returns:
a shallow copy of this LinkedList instance
See Also:
Cloneable
Related Post
Comments