![]() ![]() List studentList = new ArrayList(Arrays.asList(students)) 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. ![]() 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”. Now we have studentList which is a list of student (“Chintu”, “Sai”, “Babu”). List studentList = Arrays.asList(students) Let’s say we have an array of String and we create a list out of it. But I bet very few of us know the impact of doing this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |