Gamelib/src/main/java/uulm/teamname/marvelous/gamelibrary/ArrayTools.java

21 lines
713 B
Java

package uulm.teamname.marvelous.gamelibrary;
import java.util.ArrayList;
import java.util.Arrays;
/** Provides various tools for Arrays. */
public class ArrayTools {
/**
* Returns a variable-size array list backed by the specified array without allocating more memory than necessary.
* @param <E> the class of the objects in the array
* @param a the array by which the list will be backed
* @return a list view of the specified array
* @throws NullPointerException if the specified array is {@code null}
*/
public static <E> ArrayList<E> toArrayList(E[] a) {
ArrayList<E> l = new ArrayList<>(a.length);
l.addAll(Arrays.asList(a));
return l;
}
}