我的代码转到最后一个arraylist:
if (listItem.get(listItem.size() - 1).SortNo > 0) {
while (listItem.get(0).SortNo == 0) {
DTO_NightClinic dt = listItem.get(0);
listItem.remove(0);
listItem.add(dt);
}
}
Run Code Online (Sandbox Code Playgroud)
但通常listItem.remove(0);不起作用.第一项仍然存在于arraylist的第一个位置.
Collections.rotate(list, -1);
Run Code Online (Sandbox Code Playgroud)
只需使用旋转-1放置它就可以做你想要的
输入:
1, 2, 3, 4
Run Code Online (Sandbox Code Playgroud)
输出:
2, 3, 4, 1
Run Code Online (Sandbox Code Playgroud)
有关集合的更多信息#rotation(java.util.List,int)
| 归档时间: |
|
| 查看次数: |
2805 次 |
| 最近记录: |