Collections.reverse()vs Lists.reverse()哪一个更快? [英] Collections.reverse() vs Lists.reverse() which one is faster?

查看:315
本文介绍了Collections.reverse()vs Lists.reverse()哪一个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下问题感兴趣:Collections.reverse()vs Lists.reverse()哪个更快?

I am interested in following question: Collections.reverse() vs Lists.reverse() which one is faster?

谢谢.

推荐答案

他们做不同的事情.

Collections.reverse接受可变列表并颠倒其顺序.这需要线性时间.必须.

Collections.reverse takes a mutable list and reverses its order. It takes linear time. It has to.

番石榴的Lists.reverse返回反转列表的视图.它以固定的时间返回,但是您将为每个操作付出视图的(小)开销.

Guava's Lists.reverse returns a view of the list that is reversed. It returns in constant time, but you'll pay the (small) overhead of the view for each operation.

这篇关于Collections.reverse()vs Lists.reverse()哪一个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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