Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.AbstractList; import java.util.ArrayList; import java.util.List; public class Main { /** * takes an int array and returns a List of Integer backed by the array * @param a * @return */ public static List<Integer> asList(final int[] a) { return new AbstractList<Integer>() { public Integer get(int i) { return a[i]; } // Throws NullPointerException if val == null public Integer set(int i, Integer val) { Integer oldVal = a[i]; a[i] = val; return oldVal; } public int size() { return a.length; } }; } /** * takes a float array and returns a List of Float backed by the array * @param a * @return */ public static List<Float> asList(final float[] a) { return new AbstractList<Float>() { public Float get(int i) { return a[i]; } // Throws NullPointerException if val == null public Float set(int i, Integer val) { Float oldVal = a[i]; a[i] = val; return oldVal; } public int size() { return a.length; } }; } public static <T> List<T> asList(T... items) { ArrayList<T> list = new ArrayList<T>(items.length); if (items != null) { for (T item : items) { list.add(item); } } return list; } }