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);
|
}
|
}
|
}
|