com.autonomouslogic.commons.ListUtil Maven / Gradle / Ivy
package com.autonomouslogic.commons;
import com.autonomouslogic.commons.collection.ConcatList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ListUtil {
private ListUtil() {}
/**
* Concatenates the supplied list without explicitly copying every single element.
* Limited functionality is provided for interacting with the underlying lists.
* @param lists the lists to concatenate
* @return a concatenated list instance
* @param the list element type
*/
public static ConcatList concat(List... lists) {
return new ConcatList<>(List.of(lists));
}
/**
* Concatenates the supplied lists into an {@link ArrayList} by copying every element.
* @param lists the lists to concatenate
* @return a concatenated list copy
* @param the list element type
*/
public static List concatCopy(List... lists) {
var n = Arrays.stream(lists).mapToInt(List::size).sum();
List concat = new ArrayList<>(n);
for (List list : lists) {
concat.addAll(list);
}
return concat;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy