2806 }
2807
2808 // Misc
2809
2810 /**
2811 * Returns a fixed-size list backed by the specified array. (Changes to
2812 * the returned list "write through" to the array.) This method acts
2813 * as bridge between array-based and collection-based APIs, in
2814 * combination with {@link Collection#toArray}. The returned list is
2815 * serializable and implements {@link RandomAccess}.
2816 *
2817 * <p>This method also provides a convenient way to create a fixed-size
2818 * list initialized to contain several elements:
2819 * <pre>
2820 * List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
2821 * </pre>
2822 *
2823 * @param a the array by which the list will be backed
2824 * @return a list view of the specified array
2825 */
2826 public static <T> List<T> asList(T... a) {
2827 return new ArrayList<>(a);
2828 }
2829
2830 /**
2831 * @serial include
2832 */
2833 private static class ArrayList<E> extends AbstractList<E>
2834 implements RandomAccess, java.io.Serializable
2835 {
2836 private static final long serialVersionUID = -2764017481108945198L;
2837 private final E[] a;
2838
2839 ArrayList(E[] array) {
2840 if (array==null)
2841 throw new NullPointerException();
2842 a = array;
2843 }
2844
2845 public int size() {
|
2806 }
2807
2808 // Misc
2809
2810 /**
2811 * Returns a fixed-size list backed by the specified array. (Changes to
2812 * the returned list "write through" to the array.) This method acts
2813 * as bridge between array-based and collection-based APIs, in
2814 * combination with {@link Collection#toArray}. The returned list is
2815 * serializable and implements {@link RandomAccess}.
2816 *
2817 * <p>This method also provides a convenient way to create a fixed-size
2818 * list initialized to contain several elements:
2819 * <pre>
2820 * List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
2821 * </pre>
2822 *
2823 * @param a the array by which the list will be backed
2824 * @return a list view of the specified array
2825 */
2826 @SafeVarargs
2827 public static <T> List<T> asList(T... a) {
2828 return new ArrayList<>(a);
2829 }
2830
2831 /**
2832 * @serial include
2833 */
2834 private static class ArrayList<E> extends AbstractList<E>
2835 implements RandomAccess, java.io.Serializable
2836 {
2837 private static final long serialVersionUID = -2764017481108945198L;
2838 private final E[] a;
2839
2840 ArrayList(E[] array) {
2841 if (array==null)
2842 throw new NullPointerException();
2843 a = array;
2844 }
2845
2846 public int size() {
|