Is there a way to create a list of primitive int or any primitives in java like following?
List myList = new ArrayList();
You can use primitive collections available in Eclipse Collections. Eclipse Collections has List
, Set
, Bag
and Map
for all primitives. The elements in the primitive collections are maintained as primitives and no boxing takes place.
You can initialize a IntList like this:
MutableIntList ints = IntLists.mutable.empty();
You can convert from a List
to IntList
like this:
List integers = new ArrayList<>();
MutableIntList ints = ListAdapter.adapt(integers).collectInt(each -> each);
Note: I am a contributor to Eclipse Collections.