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

22 lines
706 B
Java
Raw Normal View History

package uulm.teamname.marvelous.gamelibrary;
import java.util.ArrayList;
/** 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);
for(E e: a) {
l.add(e);
}
return l;
}
}