How to split a string array into small chunk arrays in java?

前端 未结 12 1960
春和景丽
春和景丽 2020-12-05 05:15

Below is the example of the code snippet which needs the help

Example:

[1,2,3,4,5]
  • if the chunk size is 1,
12条回答
  •  感动是毒
    2020-12-05 05:35

       for(int i=0;irow = new ArrayList();
        int k=0;
        while(k < chunksize){
            chunk.add(list.get(i));
            i++;
            k++;
        }
        System.out.println(chunk);
        nestedlist.add(chunk);
    }   
    

    where list is a 1 dimension array and chunk is a nested array of size chunksize

提交回复
热议问题