如何获取ArrayList的最后一个值 [英] How to get the last value of an ArrayList

查看:39
本文介绍了如何获取ArrayList的最后一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 ArrayList 的最后一个值?

How can I get the last value of an ArrayList?

我不知道 ArrayList 的最后一个索引.

I don't know the last index of the ArrayList.

推荐答案

以下是List 接口(ArrayList 实现):

The following is part of the List interface (which ArrayList implements):

E e = list.get(list.size() - 1);

E 是元素类型.如果列表为空,get 会抛出一个 IndexOutOfBoundsException.您可以在此处找到整个 API 文档.

E is the element type. If the list is empty, get throws an IndexOutOfBoundsException. You can find the whole API documentation here.

这篇关于如何获取ArrayList的最后一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆