

And also we can add/remove element to this list. It is the method of the Java Arrays class that belongs to java.util package.

This way, we create a independent copy of the array which means if we overwrite the element of the list it won’t effect the original array. List studentList = new ArrayList(Arrays.asList(students))
Arrays aslist update#
And also it is not copied or created, it is just view of the same array, so if you update the value of an element in the list it will also change the element in the original array.
%E6%96%B9%E6%B3%95.png)
We can’t modify it’s length thus adding or removing is not allowed. When we do Arrays.asList(array) it creates a fixed-size list backed by the specified array. We weren’t expecting this right? What happened ? What do we get? We get an UnsupportedOperationException exception. Let’s try to add or remove an item from the list studentList.remove(0) Guess what, both got updated, but we only wanted to update the list right? Now check both students and studentList . Now let’s update our first element of the list to “Chittibabu”. This method returns a list view of the specified array. This method acts as bridge between array-based and collection-based APIs. Now we have studentList which is a list of student (“Chintu”, “Sai”, “Babu”). Java Arrays - asList () Method Description. List studentList = Arrays.asList(students) It is mostly used to create list from array of any type. This method acts as a channel between array-based and collection-based API. Let’s say we have an array of String and we create a list out of it. Java Arrays asList () Method In this tutorial, we will learn about asList () method from the Arrays class located into java.util package with some intuitive examples. But I bet very few of us know the impact of doing this. New Document( "name", "XYZ Steak Buffet").append( "contact", new Document().append( "phone", "22").append( "email", "location", Arrays.asList(- 73.9799932, 40.7660886))).append( "stars", 3).append( "categories", Arrays.Many of us might have used Arrays.asList to create a List with given array, it’s a very short way to create a list.
