Java LinkedList void add(int index,Object o)方法,带示例

LinkedList void add(int index,Object o)方法 (LinkedList void add(int index, Object o) method)

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

    该方法在java.util.Collection包中可用,在这里, Collection是一个接口。

  • In this method, the index is the position where we have to insert the element and Object is the element of the LinkedList.

    在此方法中,索引是我们必须插入元素的位置,而Object是LinkedList的元素。

  • This method is used to insert an object at the specified position in the linked list.

    此方法用于在链接列表的指定位置插入对象。

  • Index position starts from 0.

    索引位置从0开始。

Syntax:

句法:

    void add(int index , Object o){
}

Parameter(s):

参数:

We can pass two arguments as a parameter in the method and the object will add at the specified position of the linked list.

我们可以在方法中传递两个参数作为参数,并且该对象将添加到链接列表的指定位置。

Return value:

返回值:

The return type of this method is void that means this method returns nothing after execution.

该方法的返回类型为void ,这意味着该方法在执行后不返回任何内容。

Java程序演示LinkedList add(int index,Object o)方法的示例 (Java program to demonstrate example of LinkedList add(int index, Object o) method)

import java.util.LinkedList;
public class LinkList {
public static void main(String[] args) {
LinkedList list = new LinkedList();
// use add() method to add few elements in the list 
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.add(50);
//  Current list Output
System.out.println("The Current list is:" + list);
// Add new elements at index 2 i.e. The position of 
// newly inserted element is at the third position 
// of the linked list and here index is 2 and index starts from 0  
list.add(2, 25);
//  New list Output 
System.out.println("The new List is:" + list);
}
}

Output

输出量

D:\Programs>javac LinkList.java
D:\Programs>java LinkList2
The Current list is:[10, 20, 30, 40, 50]
The new List is:[10, 20, 25, 30, 40, 50]

翻译自: https://www.includehelp.com/java/linkedlist-void-add-int-index-object-o-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546210.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何生成高性能的短链接?

前言今天,我们来谈谈如何设计一个高性能短链系统,短链系统设计看起来很简单,但每个点都能展开很多知识点,也是在面试中非常适合考察侯选人的一道设计题,本文将会结合我们生产上稳定运行两年之久的高性能短链系统给大家…

iOS 技术官方 QA

2019独角兽企业重金招聘Python工程师标准>>> Q: 在静态库中使用catagory分类运行时提示"selector not recognized" A: 需要配置下project/target属性 Q: 在iOS7以后怎么截图 A: iOS7 提供了相关API实现截图功能,如:-drawViewHierarchyInRect:a…

Python日历模块| weekheader()方法与示例

Python calendar.weekheader()方法 (Python calendar.weekheader() Method) weekheader() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and returns a header containing the abbreviated names of the weekday. weekhe…

IPsec IKEv2(HCIP)

目录 一、IKE介绍 1、IKE介绍 2、IKE的主要作用 3、IKE与IPsec关系 二、IKE基础内容 1、IEK的身份认证方法 数据源认证 预共享密钥PSK 数字证书 数字信封 EAP(IKEv2支持) 数字证书CA如何实现身份认证? 2、IKEv1介绍 IKEv1介绍 IKEv1第一阶段介绍 IKEv1第二阶段…

9个小技巧让你的 if else看起来更优雅

if else 是我们写代码时,使用频率最高的关键词之一,然而有时过多的 if else 会让我们感到脑壳疼,例如下面这个伪代码: 是不是很奔溃?虽然他是伪代码,并且看起来也很夸张,但在现实中,…

poj 3254 状压dp

E -Corn FieldsTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Practice POJ 3254Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels…

第一弹!安利10个让你爽到爆的IDEA必备插件!

大家好,此篇文章中我会介绍10个非常不错的IDEA插件以及它们常见功能的使用方法。这一期内容搞 Gif 动态图花了很久,很多Gif图片上传到微信还提示过大,所以很多地方重新又录制了一遍Gif图。概览:IDE Features Trainer—IDEA交互式教…

C程序对整数中设置为1的位数进行计数

Problem statement: Write a C program to count number of bits set to 1 in an Integer. 问题陈述:编写一个C程序来计算Integer中设置为1的位数 。 Solution: We can use bitwise operator here to solve the problem. 解决方案:我们可以在这里使用按…

String性能提升10倍的几个方法!(源码+原理分析)

这是我的第 54 篇原创文章。String 类型是我们使用最频繁的数据类型,没有之一。那么提高 String 的运行效率,无疑是提升程序性能的最佳手段。我们本文将从 String 的源码入手,一步步带你实现字符串优化的小目标。不但教你如何有效的使用字符串…

日期getTime()方法以及JavaScript中的示例

JavaScript Date getTime()方法 (JavaScript Date getTime() method) getTime() method is a Dates class method and it is used to get the time in milliseconds from 1st January 1970. getTime()方法是Date的类方法,用于获取从1970年1月1 日开始的时间(以毫秒为…

制作openstack-centos镜像

一、准备工作我在计算节点上面制作镜像,计算节点为centos6.3 64位系统1.安装底层支持包yum groupinstall Virtualization "Virtualization Client"yum install libvirt2.下载或从本地上传进去一个完整的系统镜像mkdir /openstack-p_w_picpathcd /openstac…

一文彻底搞懂Java中的值传递和引用传递!

关于Java中方法间的参数传递到底是怎样的、为什么很多人说Java只有值传递等问题,一直困惑着很多人,甚至我在面试的时候问过很多有丰富经验的开发者,他们也很难解释的很清楚。我很久也写过一篇文章,我当时认为我把这件事说清楚了&a…

g++默认参数_C ++默认参数| 查找输出程序| 套装1

g默认参数Program 1: 程序1&#xff1a; #include <iostream>using namespace std;int sum(int X, int Y 20, int Z 30){return (X Y Z);}int main(){int A 0, B 0;A sum(5, 10);B sum(10);cout << A << " " << B;return 0;}Output…

c语言指针灵活性管窥

最近看到mit的[urlhttp://pdos.csail.mit.edu/6.828/2010/]操作系统课程网站[/url],其[urlhttp://pdos.csail.mit.edu/6.828/2010/labs/lab1/]实验一[/url] 中练习四&#xff08;exercise 4&#xff09;中有一个关于指针使用的代码&#xff1a;#include <stdio.h>#includ…

近100个Spring/SpringBoot常用注解汇总!

作者 | Guide来源 | JavaGuide&#xff08;微信公众号&#xff09;毫不夸张地说&#xff0c;这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景。对于每一个注解我都说了具体用法&#xff0c;掌握搞懂&#xff0c;使用 SpringBoot 来开发项…

虚拟化之vmware-vsphere (web) client

两种客户端 vsphere client 配置》软件》高级设置里的变量 uservars.supressshellwarning1 vsphere web client 安装完vSphere Web Client后&#xff0c;在浏览器地址栏输入https://localhost:<9443 或者你选择的其他端口>/admin-app/就可以访问vSphere Web Client管理工…

用贪婪算法解决背包问题_解决主要算法问题的贪婪策略

用贪婪算法解决背包问题Introduction: 介绍&#xff1a; Lets start the discussion with an example that will help to understand the greedy technique. If we think about playing chess, when we make a move we think about the consequences of the move in future st…

HashMap 的 7 种遍历方式与性能分析!(强烈推荐)

这是我的第 56 篇原创文章随着 JDK 1.8 Streams API 的发布&#xff0c;使得 HashMap 拥有了更多的遍历的方式&#xff0c;但应该选择那种遍历方式&#xff1f;反而成了一个问题。本文先从 HashMap 的遍历方法讲起&#xff0c;然后再从性能、原理以及安全性等方面&#xff0c;来…

BBcode 相关资源索引

VeryCD社区BBCode使用指南 BBcode Reference BBcodewikipedia

Why is HttpContext.Current null after await?

今天在对项目代码进行异步化改进的时候&#xff0c;遇到一个奇怪的问题&#xff08;莫笑&#xff0c;以前没遇过&#xff09;&#xff0c;正如标题一样&#xff0c;HttpContext.Current 在 await 异步执行之后&#xff0c;就会变为 null。 演示代码&#xff1a; public async T…