Arrays.asList() vs Collections.singletonList()

后端 未结 3 2042
深忆病人
深忆病人 2020-12-07 09:18

Is there an advantage (or much of a difference) to using Arrays.asList(something) over Collections.singletonList(something) to make a list containing one item? The latter ma

3条回答
  •  不知归路
    2020-12-07 09:45

    I would just add that the singletonlist is not backed by an array and just has a reference to that one item. Presumably, it would take less memory and can be significant depending on the number of lists you want to create.

提交回复
热议问题