🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 在 Java 中克隆一个通用的`LinkedList` > 原文: [https://beginnersbook.com/2014/08/clone-a-generic-linkedlist-in-java/](https://beginnersbook.com/2014/08/clone-a-generic-linkedlist-in-java/) #### 示例 ```java import java.util.LinkedList; class LinkedListClone { public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // Adding elements to the LinkedList list.add("Element1"); list.add("Element2"); list.add("Element3"); list.add("Element4"); // Displaying LinkedList elements System.out.println("LinkedList elements: "+list); // Creating another list LinkedList<String> list2 = new LinkedList<String>(); // Clone list to list2 /* public Object clone(): Returns a shallow copy of this * LinkedList. (The elements themselves are not cloned.) */ list2 = (LinkedList)list.clone(); // Displaying elements of second LinkedList System.out.println("List 2 Elements: "+list2); } } ``` **输出:** ```java LinkedList elements: [Element1, Element2, Element3, Element4] List 2 Elements: [Element1, Element2, Element3, Element4] ```