Test.java 872 Bytes
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("-------------------");
        }



    }
}