比如有一个list,里面有“1, 2, 3, 4, 5, 6, 7, 8”这八个元素,再给一个int数值,比如是3,那打印结果就是
第一次:1, 2, 3
第二次:4, 5, 6
第三次:7, 8, 1
第四次:2, 3, 4
依次类推...
public static void main(String[] args) { int strength = 3; List<Integer> indexList = new ArrayList<>(); List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); int size = list.size(); int count = 0; for (int i = 0; i < 32; i++) { for (int j = 0; j < strength; j++) { int index = (count + j) % size; indexList.add(index); } for (int m = 0; m < indexList.size(); m++) { Integer integer = indexList.get(m); System.out.println(list.get(integer)); } System.out.println("---------------------"); count+=strength; indexList.clear(); } }
标签:count,strength,indexList,int,list,给定,size From: https://www.cnblogs.com/shamo89/p/17296500.html