如题:
Eg:
import java.util.*;
public class linkedListCloneTask{
public static void main(String[] args) {
// create a LinkedList
LinkedList list1 = new LinkedList();
// add some elements
list1.add("Hello");
list1.add(2);
list1.add("Chocolate");
list1.add("10");
// print the list
System.out.println("LinkedList 1:" + list1);
// create a second LinkedList
LinkedList list2 = new LinkedList();
// clone list1
list2 = (LinkedList) list1.clone() ;
// 这里注意,有没有.clone()结果都是一样的,那还要.clone()做什么,求解!
// print list2
System.out.println("LinkedList 2:" + list2);
}
}
//*****************结果********************
//LinkedList 1:[Hello, 2, Chocolate, 10]
//LinkedList 2:[Hello, 2, Chocolate, 10]
//****************************************
Java linkedlist clone()
------解决方案--------------------