功能描述
一个链表中保存多个不同长度的数组, 根据一个索引值, 能取到对应的元素所在的数组下标
1 | public static int[] calcIndexArr(final List<String[]> list, int index) { |
测试方法:1
2
3
4
5
6
7
8
9
10
11public void testCalcIndexArr() {
List<String[]> list = new ArrayList<String[]>();
list.add(new String[2]);
list.add(new String[4]);
list.add(new String[1]);
for (int i = 0; i < 30; i++) {
int arr[] = RandName.calcIndexArr(list, i);
assertEquals(3, arr.length);
System.out.println(arr[0] + "," + arr[1] + "," + arr[2]);
}
}
测试结果:
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0
1,2,0
1,3,0
0,0,0
0,1,0
0,2,0
0,3,0
1,0,0
1,1,0