1.你可以新建一个list
java
List<Integer> list=new ArrayList<>();
int i=0;
while (i<100){
list.add(i++);
}
List<Integer> subList = list.subList(list.size()-1, list.size());
System.out.println("原list大小--"+list.size());
System.out.println("新list大小--"+subList.size());
System.out.println("原list最后的数字--"+list.get(list.size()-1));
System.out.println("新list的第一个数字--"+subList.get(0));
2.你确实不想新建一个要在原list做修改
java
List<Integer> list=new ArrayList<>();
int i=0;
while (i<100){
list.add(i++);
}
System.out.println("原list大小--"+list.size());
System.out.println("原list最后的数字--"+list.get(list.size()-1));
list.subList(0, list.size()-1).clear();
System.out.println("新list大小--"+list.size());
System.out.println("新list最后的数字--"+list.get(0));