Difference between Arrays asList array and new ArrayList Integer Arrays asList array

0 votes

What's the difference in these two ways?

  1. List<Integer> list1 = new ArrayList<Integer>(Arrays.asList(ia));
  2. List<Integer> list2 = Arrays.asList(ia);

Note that ia refers to integer array

I have come to find that some operations are not allowed for list2. Why is that the case? How does it get stored into the memory?

If I shuffle lists, ist1 doesn't change the original array, but list2 does. So list2 is confusing for me.

How does the ArrayList being upcasted to list is different than creating a new ArrayList?

list1 differs from (1)
ArrayList<Integer> list1 = new ArrayList<Integer>(Arrays.asList(ia));
Aug 5, 2022 in Java by krishna
• 2,820 points

edited 5 days ago 13 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP