向量类setElementAt()方法 (Vector Class setElementAt() method)

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

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

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

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

  • setElementAt() 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.

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

  • setElementAt() method may throw an exception at the time of setting an element.

    setElementAt()方法在设置元素时可能会引发异常。

    ArrayIndexOutOfBoundsException: This exception may throw when the given first parameter is not in a range.

    ArrayIndexOutOfBoundsException :如果给定的第一个参数不在范围内,则可能引发此异常。

Syntax:

句法:

    public void setElementAt(Element ele, int indices);

Parameter(s):

参数:

  • Element ele – represents the element to be set at the given indices.

    元素ele –表示要在给定索引处设置的元素。

  • int indices – represents the indices of the given element to be set.

    int index –表示要设置的给定元素的索引。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example
// of void setElementAt(Element ele, int indices) method
// of Vector
import java.util.*;
public class SetElementAtOfVector {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 setElementAt() method is to
// set the element at the given indices
v.setElementAt("SFDC", 2);
// Display updated vector
System.out.println("v.setElementAt(SFDC, 2): " + v);
}
}

Output

输出量

v: [C, C++, JAVA]
v.setElementAt(SFDC, 2): [C, C++, SFDC]

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

Java Vector setElementAt()方法与示例相关推荐

  1. java vector.isempty,Java Vector isEmpty()方法与示例

    向量类isEmpty()方法isEmpty()方法在java.util包中可用. isEmpty()方法用于检查此Vector是"空"还是"非空". isEmp ...

  2. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

最新文章

  1. 阻塞队列的使用案例-注册成功后增加积分
  2. Storm 01_初识初知
  3. opengl绘制长方体线框_OpenGL绘制长方体
  4. 【ABAP系列】SAP ABAP模块-任意report作为附件以邮件形式发送
  5. Ubuntu上安装Samba服务器实现家庭共享
  6. Atcoder 077E - guruguru(线段树+dp)
  7. 直接播放H264视频流的方法或工具
  8. 电脑硬盘怎么测试软件,如何通过软件检测电脑硬盘坏道?
  9. 阿里巴巴Java开发规范手册(详尽版)——免费下载
  10. keepalived的双机热备(主从模式)-主机宕机备机无法替代踩坑
  11. CCF计算机职业资格认证系列一CCF软件能力认证
  12. Lomo 照片特效 Lr 预设 Lomo Lightroom Presets
  13. 【无标题】2021年烷基化工艺证考试及烷基化工艺操作证考试
  14. Kylin高级主题-Cube构建算法介绍(逐层算法和快速算法)
  15. 二手交易APP开发主要功能有哪些?(一)
  16. NAT模式、路由模式、桥接模式 区别对比
  17. ubuntu和windows复制粘贴
  18. HDMI 2.1特性
  19. Matplotlib绘制圆环图
  20. Tushare积分不够2000利用日线行情数据计算涨跌停价格

热门文章

  1. mysql key_len_浅谈mysql explain中key_len的计算方法
  2. rk3128屏幕占空比参数设置_瑞芯微RK3128芯片怎么样 性能全面解读
  3. 二叉树的层序遍历和前中后序遍历代码 迭代/递归
  4. linux查看队列 msg,linux第10天 msg消息队列
  5. ming window 交叉编译_opencv3编译pc端及交叉编译arm端
  6. c语言的程序结构语序,第3章 C语序结构.doc
  7. rocketmq java例子_SpringBoot和RocketMQ的简单实例
  8. 儿童吹泡泡水简单配方_儿童吹泡泡玩具水怎么制作
  9. python基本命令range_Python的Range()函数(指南)
  10. sed教程入门与实例练习(二)