Add multiple items to already initialized arraylist in java

前端 未结 6 1707
温柔的废话
温柔的废话 2020-11-27 16:45

I\'m googling it and can\'t seem to find the syntax. My arraylist might be populated differently based on a user setting, so I\'ve initialized it



        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 16:56

    I believe the answer above is incorrect, the proper way to initialize with multiple values would be this...

    int[] otherList ={1,2,3,4,5};
    

    so the full answer with the proper initialization would look like this

    int[] otherList ={1,2,3,4,5};
    arList.addAll(Arrays.asList(otherList));
    

提交回复
热议问题