如何从排序列表中获取第一个元素? [英] How can I get a first element from a sorted list?

查看:548
本文介绍了如何从排序列表中获取第一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Collections.sort(playersList); 来排序列表。所以,我认为现在对 playersList 进行排序。但是我怎样才能获得列表的第一个元素? playersList [0] 不起作用。

I used Collections.sort(playersList); to sort a List. So, I think playersList is sorted now. But how can I get the first element of the list? playersList[0] does not work.

推荐答案

playersList.get(0)

Java具有有限的运算符多态性。所以你在 List 对象上使用 get()方法,而不是数组索引运算符( []

Java has limited operator polymorphism. So you use the get() method on List objects, not the array index operator ([])

这篇关于如何从排序列表中获取第一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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