1

In Arrays.java file. The method asList is defined as below.

 @SafeVarargs
    public static <T> List<T> asList(T... arr) {
        return new ArrayList<>(arr);
    }

Here the ArrayList constructor is invoked with an Array.(arr), new ArrayList(arr). But there is no constructor in ArrayList class which accepts Array as argument.Array class is in Collections FrameWork but doesn't implement Collection interface. The constructors in ArrayList are

ArrayList()

ArrayList(Collection<? extends E> c)

ArrayList(int initialCapacity)

can someone explain what is happening there?

0

1 Answer 1

12

It uses the constructor ArrayList(E[] array) of the private static class ArrayList<E>, which is present in the Arrays.java file.

Sign up to request clarification or add additional context in comments.

1 Comment

...and it was located immediately after the asList method!!! Just for the history

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.