Collections.reverse() vs Lists.reverse() which one is faster?

前端 未结 1 1328
暗喜
暗喜 2021-01-20 03:16

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

Thanks.

相关标签:
1条回答
  • 2021-01-20 03:35

    They do different things.

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

    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.

    0 讨论(0)
提交回复
热议问题