Java ArrayList Get()方法教程与示例

Java programming language provides List and ArrayList classes and objects in order to store multiple items in a single variable or structure. These List and ArrayList objects provide the get() method which is simply used to get an item from the List or ArrayList.

Java编程语言提供List和ArrayList类和对象,以便将多个项目存储在单个变量或结构中。 这些List和ArrayList对象提供get()方法,该方法仅用于从List或ArrayList获取项目。

get()方法语法 (get() Method Syntax)

The get() method of the ArrayList or List has the following syntax. The index numbers in Lists and ArrayLists start from 0 which means the first item or element index number is 0.

ArrayList或List的get()方法具有以下语法。 列表和数组列表中的索引号从0开始,这意味着第一项或元素的索引号为0。

ITEM OBJECT.get(int INDEX)
  • ITEM is the object which will be returned from the given OBJECT with the given INDEX number.

    ITEM是将从给定对象以给定索引号返回的对象。

  • OBJECT is the list or ArrayList object which contains items.

    OBJECT是包含项的列表或ArrayList对象。

  • int INDEX specifies the index number of the item we want to get to ITEM from the OBJECT.

    int INDEX指定我们要从OBJECT获取到ITEM的项目的索引号。

mylist.get(5)

mylist.get(5)

  • mylist is an ArrayList or List which contains multiple items.

    mylist是一个包含多个项目的ArrayList或List。

  • get(5) will return the item which index is 5.

    get(5)将返回索引为5的项目。

ArrayList的get()方法示例 (get() Method Example with ArrayList)

We will make an example with ArrayList and get() method. We will create an ArrayList named mylist and add items 10,20,30,40,50,60 to this list. Then we will use get() function to return the 2nd element of the ArrayList.

我们将使用ArrayList和get()方法作为示例。 我们将创建一个名为mylist的ArrayList并将10,20,30,40,50,60项添加到此列表中。 然后,我们将使用get()函数返回ArrayList的第二个元素。

import java.util.*;

public class Java_List_Get {
        public static void main(String[] args)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值