List反转的方法

1.list循环

java 复制代码
  List<String> strs=new ArrayList<>();
        for (int i = 0; i <100 ; i++) {
            strs.add("a"+i);
        }
        List<String> fzstrs=new ArrayList<>();
        for (int i = strs.size()-1; i >=0 ; i--) {
            fzstrs.add(strs.get(i));
        }
        System.out.println(fzstrs.get(0));
        

2.Collections.reverse(),这个反转是直接在原list反转的

java 复制代码
 List<String> strs=new ArrayList<>();
        for (int i = 0; i <100 ; i++) {
            strs.add("a"+i);
        }
        Collections.reverse(strs);//将列表反转
        System.out.println(strs.get(0));

3.谷歌guava包里的方法

java 复制代码
        List<String> strs=new ArrayList<>();
        for (int i = 0; i <100 ; i++) {
            strs.add("a"+i);
        }
        List<String> newstrs= Lists.reverse(strs);//将列表反转
        System.out.println(newstrs.get(0));
相关推荐
xiangyun6118 小时前
C++ list 模拟实现(一):手撕双向链表,从节点到迭代器
数据库·c++·算法·链表·stl·list
无忧.芙桃2 天前
C++语言原理与实践(十二):list类的底层实现
c++·windows·list
大鹏说大话4 天前
C++ STL 容器怎么选?vector、list、map、unordered_map 对比
开发语言·c++·list
by209996 天前
list:迭代器与资源管理实现的综合叙述(下)
数据结构·c++·笔记·list
by209998 天前
list 的使用:把节点、位置和操作联系起来的综合叙述(上)
数据结构·c++·笔记·list
ShineWinsu11 天前
对于Redis:List类型的解析
数据库·c++·redis·链表·缓存·面试·list
weixin1997010801612 天前
《1688物流API接口边界:logistics.trace.get 与 freight.template.list 的隐藏约束》(附Python源码)
windows·python·list
恋喵大鲤鱼13 天前
go list command
golang·list
步行cgn1 个月前
Spring 注入 List 集合详解
windows·spring·list
淡海水1 个月前
11-03-Unity-List-T-和Dictionary-TKey-TValue-的性能调优实战
算法·unity·c#·list·dictionary