Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.AbstractList;

import java.util.List;

public class Main {
    /**
     * Creates and returns an unmodifiable List that wraps the given array.
     * Changes to the array will be reflected in the List.
     * @param arr The array to wrap as a List
     * @return an unmodifiable List that wraps the array
     * @throws NullPointerException if the array is null
     */
    public static List<Double> listFromDoubleArray(final double[] arr) {
        if (arr == null)
            throw new NullPointerException("array cannot be null");
        return new AbstractList<Double>() {
            @Override
            public Double get(int index) {
                return arr[index];
            }

            @Override
            public int size() {
                return arr.length;
            }
        };
    }
}