博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java LinkedList对象的clone()方法和示例
阅读量:2531 次
发布时间:2019-05-11

本文共 1743 字,大约阅读时间需要 5 分钟。

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 1 LinkedList l1 = new LinkedList(); // Create an object of linked list 2 LinkedList 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 Output System.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 manually l2 = (LinkedList) l1.clone(); // Linked list 2 Output System.out.println("The Linked List 2 is:" + l2); }}

Output

输出量

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

翻译自:

转载地址:http://kuxzd.baihongyu.com/

你可能感兴趣的文章
DSB
查看>>
Java中的阻塞队列
查看>>
前端软件sublime的一些常用快捷键
查看>>
openssl 升级
查看>>
2017.10.30 天晴 昨天十公里没减肥
查看>>
Git 打标签(分布式版本控制系统)
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
HttpClient读取数据乱码的解决方案
查看>>
如何使用FireBug插件查询元素的xPath属性
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------>Android嵌入图像InsetDrawable的使用方法
查看>>