Pu Zhibing
2025-02-27 f0a9a41697a8568e8b3bd3436c450e68b3298916
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.panzhihua.common.utlis;
 
/**
 * 应用模块名称
 * <p>
 * 代码描述
 * <p>
 * Copyright: Copyright (C) 2022 XXX, Inc. All rights reserved.
 * <p>
 * Company: 成都呐喊信息技术有限公司
 * <p>
 *
 * @author manailin
 * @since 2022/2/17 14:33
 */
import java.util.Objects;
import java.util.function.BiConsumer;
 
/**
 *
 * @author yangzhilong
 * @date 7/15/2019
 */
public class ForEachUtils {
 
    /**
     *
     * @param <T>
     * @param startIndex
     *            开始遍历的索引
     * @param elements
     *            集合
     * @param action
     */
    public static <T> void forEach(int startIndex, Iterable<? extends T> elements,
        BiConsumer<Integer, ? super T> action) {
        Objects.requireNonNull(elements);
        Objects.requireNonNull(action);
        if (startIndex < 0) {
            startIndex = 0;
        }
        int index = 0;
        for (T element : elements) {
            index++;
            if (index <= startIndex) {
                continue;
            }
 
            action.accept(index - 1, element);
        }
    }
}