All Downloads are FREE. Search and download functionalities are using the official Maven repository.

wf.utils.java.data.list.ListUtils Maven / Gradle / Ivy

There is a newer version: 3.3.4
Show newest version
package wf.utils.java.data.list;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class ListUtils {

    public static  List copyOfRange(List list, int from, int to) {
        if (from < 0 || from >= list.size() || to < 0 || to >= list.size() || from > to)
            throw new IllegalArgumentException("Illegal extraction bounds");

        List result = new ArrayList<>(to - from + 1);

        for (int i = from; i <= to; i++)
            result.add(list.get(i));

        return result;
    }


    public static  void batchForEach(List list, int batchSize, Consumer> consumer) {
        for (int i = 0; i < list.size(); i += batchSize) {
            int end = Math.min(i + batchSize, list.size());
            consumer.accept(list.subList(i, end));
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy