RAA*_*AAM 4 java collections arraylist
嗨我怎样才能获得list.i的最后三个值
stringAry.get(stringAry.size()-1);
Run Code Online (Sandbox Code Playgroud)
但它只显示列表的最后一项.我们怎样才能获得列表的最后三个值.请指导我.是否可以将所有这三个值存储在String数组中
Mar*_*aux 11
if (stringAry.size() >= 3) // Make sure you really have 3 elements
{
List<String> array = new ArrayList<String>();
array.add(stringAry.get(stringAry.size()-1)); // The last
array.add(stringAry.get(stringAry.size()-2)); // The one before the last
array.add(stringAry.get(stringAry.size()-3)); // The one before the one before the last
System.out.println(array);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9872 次 |
| 最近记录: |