Create a List of primitive int?

后端 未结 10 1928
夕颜
夕颜 2020-11-27 12:43

Is there a way to create a list of primitive int or any primitives in java like following?

List myList = new ArrayList();
10条回答
  •  渐次进展
    2020-11-27 13:09

    This is not possible. The java specification forbids the use of primitives in generics. However, you can create ArrayList and call add(i) if i is an int thanks to boxing.

提交回复
热议问题