Java Vector insertElementAt()方法与示例

矢量类insertElementAt()方法 (Vector Class insertElementAt() method)

  • insertElementAt() method is available in java.util package.

    insertElementAt()方法在java.util包中可用。

  • insertElementAt() method is used to set the given element (ele) at the given (indices) in thid Vector.

    insertElementAt()方法用于在Vector的给定(索引)处设置给定元素(ele)。

  • insertElementAt() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    insertElementAt()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • insertElementAt() method may throw an exception at the time of the inserting element.

    insertElementAt()方法在插入元素时可能会引发异常。

    ArrayIndexOutOfBoundsException: This exception may throw when the given indices are not in a range.

    ArrayIndexOutOfBoundsException :如果给定索引不在范围内,则可能引发此异常。

Syntax:

句法:

    public void insertElementAt(Element ele, int indices);

Parameter(s):

参数:

  • Element ele – represents the element to be added.

    元素ele –表示要添加的元素。

  • int indices – represents the position of inserted element.

    int索引 –表示插入元素的位置。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void insertElementAt(Element ele, int indices)
// method of Vector 
import java.util.*;
public class InsertElementAtOfVector {
public static void main(String[] args) {
// Instantiates a Vector object  with
// initial capacity of "10"
Vector < String > v = new Vector < String > (10);
// By using add() method is to add the
// elements in this v
v.add("C");
v.add("C++");
v.add("JAVA");
// Display Vector
System.out.println("v: " + v);
// By using insertElementAt("SFDC", 1) method is
// to insert the given object "SFDC" at the given
// indices "1"
v.insertElementAt("SFDC", 1);
// Display updated vector
System.out.println("v.insertElementAt(SFDC, 1): " + v);
}
}

Output

输出量

v: [C, C++, JAVA]
v.insertElementAt(SFDC, 1): [C, SFDC, C++, JAVA]

翻译自: https://www.includehelp.com/java/vector-insertelementat-method-with-example.aspx

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

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

相关文章

Python---查找序列的最长递增子序列

查找序列的最长递增子序列 什么是序列的最长递增子序列&#xff1f; 答&#xff1a;在一个数值序列中&#xff0c;找到一个子序列&#xff0c;使得这个子序列元素的数值依次递增&#xff0c;并且这个子序列的长度尽可能地大。这就是所谓的最长递增子序列 from itertools impo…

SendMessage和PostMessage

SendMessage 和 PostMessage 的区别 &#xff11;、首先是返回值意义的区别&#xff0c;我们先看一下 MSDN 里的声明&#xff1a; LRESULT SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);BOOL PostMessage( HWND hWnd…

ffmpeg-从mp4、flv、ts文件中提取264视频流数据

ffmpeg-从mp4、flv、ts文件中提取264视频流数据 main.c #include <stdio.h> #include <libavutil/log.h> #include <libavformat/avio.h> #include <libavformat/avformat.h>void proc(int need_to_annexb, char* in_file, char* out_file) {AVForma…

java timezone_Java TimeZone getDSTSavings()方法与示例

java timezoneTimeZone类的getDSTSavings()方法 (TimeZone Class getDSTSavings() method) getDSTSavings() method is available in java.util package. getDSTSavings()方法在java.util包中可用。 getDSTSavings() method is used to get the number of time differences in …

Photoshop 保存PNG格式交错和不交错有差别

1.PNG格式是由Netscape公司开发出来的格式&#xff0c;可以用于网络图像&#xff0c;但它不同于GIF格式图像只能保存256色&#xff0c;PNG格式可以保存24位的真彩色图像&#xff0c;并且支持透明背景和消除锯齿边缘的功能&#xff0c;可以在不失真的情况下压缩保存图像。但由于…

线索化二叉树(代码 、分析 、汇编)

目录&#xff1a;代码&#xff1a;分析&#xff1a;汇编&#xff1a;代码&#xff1a; BTree.h BTree.c 二叉树&#xff08;多路平衡搜索树&#xff09; SeqList.h SeqList.c 顺序表 main.c #include <stdio.h> #include <stdlib.h> #include "BTree.h&qu…

Python---寻找给定序列中相差最小的两个数字

编写函数&#xff0c;寻找给定序列中相差最小的两个数字 def getTwoClosestElements(arr):#先进行排序&#xff0c;使得相邻元素最接近#相差最小的元素必然相邻seq sorted(arr)#先进行排序dif float(inf)#无穷大#遍历所有元素&#xff0c;两两比较&#xff0c;比较相邻元素的…

ubuntu 无线 共享 上网

配置DHCP服务器 使连接到此AP的电脑 自动获取IP 1. 安装软件包&#xff1a;sudo apt-get install dhcp3-server2. 修改/etc/default/dhcp3-server配置文件INTERFACES"eth1" //eth1为无线网卡的名字3. 修改/etc/dhcp3/dhcpd.conf配置文件option domain-name-servers …

Java StringBuilder getChars()方法与示例

StringBuilder类的getChars()方法 (StringBuilder Class getChars() method) getChars() method is available in java.lang package. getChars()方法在java.lang包中可用。 getChars() method is used to copy all the characters from the given arguments (int src_st, int …

Python---利用蒙特.卡罗方法计算圆周率近似值

利用蒙特.卡罗方法计算圆周率近似值 什么是蒙特.卡罗方法&#xff1f; 答&#xff1a;蒙特卡罗方法是一种计算方法。原理是通过大量随机样本&#xff0c;去了解一个系统&#xff0c;进而得到所要计算的值。 正方形内部有一个相切的圆&#xff0c;它们的面积之比是π/4。 这里假…

不具有继承关系的Delegate如何进行类型转换?

- 引自:Artech 我们知道对于两个不具有继承关系的两个类型&#xff0c;如果没有为它们定义转换器&#xff0c;两这之间的类型转换是不允许的&#xff0c;Delegate也是如此。但是有时候我们却希望“兼容”的两种Delegate类型能够进行转换&#xff0c;比较典型的就是表示事件的De…

Java属性loadFromXML()方法与示例

属性类loadFromXML()方法 (Properties Class loadFromXML() method) loadFromXML() method is available in java.util package. loadFromXML()方法在java.util包中可用。 loadFromXML() method is used to load all the properties denoted by the XML file on the given inpu…

FLV封装格式的分析

FLV封装格式的分析&#xff0c;各种详细的参数比较多没有详细解释&#xff0c;这是总体的格式分布。详细的参数说明可以参照文档。 以flv格式内封装的音频流是aac、视频流是h264分析&#xff1a; flv文件tag部分截图&#xff1a;可以看到音频TAG、视频TAG是交错存储的

《计算机基础复习》===数据库技术基础

数据库系统三级结构&#xff1a; 数据库系统一般划分为三个抽象级&#xff1a;用户级、概念级、物理级。 1&#xff09;用户级数据库&#xff1a;对应于外模式。它是用户看到和使用的数据库&#xff0c;又称用户视图&#xff1b;用户级数据库主要由外部记录组成&#xff0c;不同…

bs架构 erp 进销存_从依赖经验到用柔性ERP,企业少走了多少弯路?

企业在面对紧急订单时&#xff0c;传统企业将面临两难问题&#xff1a;如不接受紧急订单,可能会导致潜在的顾客丢失,损失市场占有率;接受紧急订单,可能会给企业带来很多管理上的问题,如材料采购、库存管理等。而企业通过信息化手段提升生产计划与控制的柔性&#xff0c;则可从容…

Python---统计《三国演义》中出现次数较高的人物

统计《三国演义》中出现次数较高的人物。 import jieba excludes{"先主","将军","却说","荆州","二人","不可","不能","如此","忽然","下马","喊声","马…

Java RandomAccessFile close()方法与示例

RandomAccessFile类close()方法 (RandomAccessFile Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this RandomAccessFile stream and free all other system resources linked wit…

云端: 小软件大平台,绿色又安全 V0.9 Beta3(090722)

云端 是一个小软件&#xff0c;但又是一个大平台。安装云端之后&#xff0c;再使用其他软件不再需要安装——一点、下载、直接使用&#xff1b;并且&#xff0c;通过虚拟化的运行环境&#xff0c;能够保持系统长久的干净、绿色&#xff0c;并保持软件与系统的安全隔离——此方面…

MGraph图(代码、分析、汇编)

目录:代码&#xff1a;分析&#xff1a;汇编&#xff1a;MGrapth图表示有邻接矩阵的方式构成的图结构。邻接矩阵用两个数组保存数据&#xff0c;一个一维数组存储图中的顶点信息&#xff0c;一个二维数组存储图中边或弧的信息。无向图中的二维数组是个对称矩阵 1.0表示无边&…

java: 程序包lombok不存在_Java开发神器:Lombok 学习指南

点击上方“Java知音”&#xff0c;选择“置顶公众号”技术文章第一时间送达&#xff01;作者&#xff1a;semlinkerwww.segmentfault.com/a/1190000020864572一、Lombok 简介Lombok 是一款 Java 开发插件&#xff0c;使得 Java 开发者可以通过其定义的一些注解来消除业务工程中…