How to convert a Collection to List?

前端 未结 10 549
不知归路
不知归路 2020-12-07 09:04

I am using TreeBidiMap from the Apache Collections library. I want to sort this on the values which are doubles.

My method is to retrieve a

10条回答
  •  不思量自难忘°
    2020-12-07 09:18

    List list = new ArrayList(coll);
    Collections.sort(list);
    

    As Erel Segal Halevi says below, if coll is already a list, you can skip step one. But that would depend on the internals of TreeBidiMap.

    List list;
    if (coll instanceof List)
      list = (List)coll;
    else
      list = new ArrayList(coll);
    

提交回复
热议问题