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

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

问题描述

我怎样才能得到一个ArrayList的最后一个值?

How can I get the last value of an ArrayList?

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

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

推荐答案

以下是的 列表 接口(ArrayList的器具):

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

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

电子是元素类型。如果该列表是空的, GET 抛出<一个href=\"http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html\"><$c$c>IndexOutOfBoundsException.在这里你发现整个API文档

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

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

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