Test.java
872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.viontech.keliu.controller;
import cn.hutool.core.collection.ListUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2024-01-04
* Time: 14:10
*/
public class Test {
public static void main(String[] args) {
List<String> list = Arrays.asList("1","0","-1","-1");
int[] indexs = ListUtil.indexOfAll(list, "1"::equals);
for (int i = 0; i < indexs.length; i++) {
List<String> strings;
if (i == indexs.length - 1) {
strings = list.subList(indexs[i], list.size());
} else {
strings = list.subList(indexs[i],indexs[i+1]);
}
System.out.println(String.join(",", strings));
System.out.println("-------------------");
}
}
}