Add multiple items to already initialized arraylist in java

前端 未结 6 1711
温柔的废话
温柔的废话 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 17:04

    If you needed to add a lot of integers it'd proabbly be easiest to use a for loop. For example, adding 28 days to a daysInFebruary array.

    ArrayList daysInFebruary = new ArrayList<>();
    
    for(int i = 1; i <= 28; i++) {
        daysInFebruary.add(i);
    }
    

提交回复
热议问题