Java ArrayList for integers

前端 未结 8 1180
陌清茗
陌清茗 2020-12-11 00:24

I have values that I\'d like to add into an ArrayList to keep track of what numbers have shown up. The values are integers so I created an ArrayList;

ArrayLi         


        
8条回答
  •  悲&欢浪女
    2020-12-11 01:03

    Actually what u did is also not wrong your declaration is right . With your declaration JVM will create a ArrayList of integer arrays i.e each entry in arraylist correspond to an integer array hence your add function should pass a integer array as a parameter.

    For Ex:

    list.add(new Integer[3]);
    

    In this way first entry of ArrayList is an integer array which can hold at max 3 values.

提交回复
热议问题