Java LinkedList clone Example
LinkedList class clone method example. This example shows you how to use clone method.
LinkedList class clone method example.public Object clone() Returns a shallow copy of this LinkedList.
Here is the code
/**
* @ # Clone.java
* A class repersenting use to Clone method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Clone {
public static void main(String args[]) {
LinkedList list = new LinkedList();
int i = 0;
String str = "Rose India";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
System.out.println("list = " + list);
//Creat clone of the LinkedList
List list1 =(LinkedList) list.clone();
System.out.println("list1 = " + list1);
}
} |
Output
list = [0, Rose India]
list1 = [0, Rose India |
|