Java ArrayList get()方法与示例
ArrayList类的get()方法 (ArrayList Class get() method)
get() method is available in java.util package.
get()方法在java.util包中可用。
get() method is used to retrieve the element at the given index in this Arraylist.
get()方法用于检索此Arraylist中给定索引处的元素。
get() method is a non-static method so it is accessible with the class object and if we try to access the method with the class name then we will get an error.
get()方法是一种非静态方法,因此可以通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。
get() method may throw an exception at the time of returning an element of the given indices.
在返回给定索引的元素时, get()方法可能会引发异常。
IndexOutOfBoundsException:- This exception may throw when the given indices are not in a range.
IndexOutOfBoundsException:-当给定索引不在范围内时,可能引发此异常。
Syntax:
句法:
public T get(int indices);
Parameter(s):
参数:
int indices – represents the index of the element to retrieve.
int index –表示要检索的元素的索引。
Return value:
返回值:
The return type of this method is T, it returns the element at the given index in this Arraylist.
此方法的返回类型为T ,它返回此Arraylist中给定索引处的元素。
Example:
例:
// Java program to demonstrate the example
// of T get(int) method of ArrayList.
import java.util.*;
public class GetOfArrayList {public static void main(String[] args) {// Create an ArrayList with initial
// capacity of storing elements
ArrayList < String > arr_l = new ArrayList < String > (10);
// By using add() method is to add
// elements in this ArrayList
arr_l.add("C");
arr_l.add("C++");
arr_l.add("JAVA");
arr_l.add("DOTNET");
arr_l.add("PHP");
// Display ArrayList
System.out.println("ArrayList Elements :" + arr_l);
// By using get(int) method is to return the
// element at the given index in this ArrayList
String element = arr_l.get(2);
// Display Returned Element
System.out.println("arr_l.get(2) : " + element);
}
}
Output
输出量
ArrayList Elements :[C, C++, JAVA, DOTNET, PHP]
arr_l.get(2) : JAVA
翻译自: https://www.includehelp.com/java/arraylist-get-method-with-example.aspx
Java ArrayList get()方法与示例相关推荐
- java arraylist.add(),Java ArrayList add()方法与示例
ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...
- Java SubList 类 Java subList方法 Java ArrayList$SubList 方法特点 SubList 用法
Java SubList 类 Java subList方法 Java ArrayList$SubList 方法特点 SubList 用法 一.概述 在java集合中,常用ArrayList类中,若需要 ...
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- Java ArrayList indexOf() 方法 和 String indexOf() 方法区别
1.ArrayList indexOf() 方法 indexOf(Object obj) 方法返回动态数组中元素的索引值. 返回的值为: 返回在数组中最先出现 obj 元素的索引值,索引下标从0开始 ...
- java arraylist .get_Java ArrayList get()方法与示例
ArrayList类get()方法get()方法在java.util包中可用. get()方法用于检索此Arraylist中给定索引处的元素. get()方法是一个非静态方法,因此可以通过类对象进行访 ...
- java rotate,Java Collections rotate()方法与示例
集合类rotate()方法rotation()方法在java.util包中可用. rotation()方法用于将List(l)元素旋转给定距离(dis). rotation()方法是静态方法,因此可以 ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
- filepermission java,Java FilePermission getActions()方法与示例
FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...
最新文章
- Too Many Segments CF595D 贪心乱搞
- boost::asio异步模式的C/S客户端源码实现
- 互联网人的平均时长,居然这么短...
- 配置ISA Server 2006 ×××使用户轻松连接内网
- Catia V5-6R2015安装教程
- 02_JNI中Java代码调用C代码,Android中使用log库打印日志,javah命令的使用,Android.mk文件的编写,交叉编译
- Qt工作笔记-依赖于QAbstractTableModel实现自定义TableModel
- java字符串相关知识
- c语言 单片机模拟,【51单片机】普通I/O口模拟SPI口C语言程序
- java逐行读取文件_Java逐行读取文件
- python mro c3_Python的MRO以及C3线性化算法
- 数字IC设计系列----安装配置虚拟机、安装centos系统
- as(四级考试频度很大的几个用法)
- 蓝桥web模拟赛:时间管理大师
- 创建套接字socket函数的详解(sock_stream和sock_dgram的分析)
- HTML小游戏——打砖块
- win10解决IE浏览器安装不上的问题(卸载依然显示不能安装)
- Zabbix_agent的主动式和被动式
- PS 2021锁死各项AI新技术!用起来比美图秀秀更简单,几个键搞定老照片修复、变妆、绘画风格转换...
- MFC扩展DLL添加对话框资源时对话框ID是“未声明标识符”
热门文章
- html盒子模型页面居中,【静态页面架构】CSS之盒子模型
- Python 装饰器详解(下)
- Xctf练习sql注入--supersqli
- android模拟器太卡,安卓模拟器安装之后太卡怎么解决
- mocha 测试 mysql_node项目mocha自动化测试的疑问
- css动画定义,CSS3中Animation动画的定义和调用
- python中的常量可以修改吗_深入理解Python变量与常量
- 苹果6怎样打开html,苹果iPhone的Safari浏览器使用技巧图解
- violinplot如何看懂_一张图告诉你如何看懂个股大趋势
- 安装LibreOffice和字体