日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java LinkedList对象的clone()方法和示例

發布時間:2025/3/11 java 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java LinkedList对象的clone()方法和示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LinkedList對象clone()方法 (LinkedList Object clone() method)

  • This method is available in package java.util.Collection and here, Collection is an interface.

    該方法在java.util.Collection包中可用,在這里, Collection是一個接口。

  • This method is used to create a duplicate or shallow copy of the Linked list.

    此方法用于創建鏈接列表的重復副本或淺表副本。

  • In this method, we required two objects of the same type and one object will be copied in another object.

    在這種方法中,我們需要兩個相同類型的對象,并將一個對象復制到另一個對象中。

  • This method does not return an exception.

    此方法不返回異常。

Syntax:

句法:

Object clone(){}

Parameter(s):

參數:

This method does not accept any parameter.

此方法不接受任何參數。

Return value:

返回值:

The return type of this method is Object that means this method returns an instance of the linked list after execution.

該方法的返回類型為Object ,這意味著該方法在執行后返回鏈表的實例。

Java程序,演示LinkedList clone()方法的示例 (Java program to demonstrate example of LinkedList clone() method)

import java.util.LinkedList;public class LinkList {public static void main(String[] args) {// Create an object of linked list 1LinkedList l1 = new LinkedList();// Create an object of linked list 2LinkedList l2 = new LinkedList();// use add() method to add few elements in the linked list 1 l1.add(10);l1.add(20);l1.add(30);l1.add(40);l1.add(50);// Linked list 1 OutputSystem.out.println("The Linked list 1 is :" + l1);// With the help of clone() we will copy of // all the elements of linked list 1 in other // linked list 2 without inserting manuallyl2 = (LinkedList) l1.clone();// Linked list 2 OutputSystem.out.println("The Linked List 2 is:" + l2);} }

Output

輸出量

D:\Programs>javac LinkList.javaD:\Programs>java LinkList The Linked list 1 is :[10, 20, 30, 40, 50] The Linked List 2 is:[10, 20, 30, 40, 50]

翻譯自: https://www.includehelp.com/java/linkedlist-object-clone-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java LinkedList对象的clone()方法和示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。