Create a List of primitive int?

后端 未结 10 1930
夕颜
夕颜 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 12:57

    Java Collection should be collections of Object only.

    List integerList = new ArrayList();
    

    Integer is wrapper class of primitive data type int.

    more from JAVA wrapper classes here!

    U can directly save and get int to/from integerList as, integerList.add(intValue); int intValue = integerList.get(i)

提交回复
热议问题