Convert Set to List without creating new List

前端 未结 15 911
鱼传尺愫
鱼传尺愫 2020-12-07 06:43

I am using this code to convert a Set to a List:

Map> mainMap = new HashMap<>();

for (int i         


        
15条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 07:20

    Also from Guava Collect library, you can use newArrayList(Collection):

    Lists.newArrayList([your_set])
    

    This would be very similar to the previous answer from amit, except that you do not need to declare (or instanciate) any list object.

提交回复
热议问题