Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Cloud Services
AWS
Azure
Google Cloud
Salesforce
Microsoft
SAP
May 31, 2023
1. Mutability –
Arrays.asList is mutable which means that you cannot add or remove elements from the list.
However, you can modify the existing elements in the list.
Example –
String[] array = {"apple", "banana", "cherry"}; List<String> list = Arrays.asList(array); list.set(0, "orange"); // Changes "apple" to "orange"
List.of is immutable, meaning you cannot add, remove or modify elements in the list.
If you try to modify the list, you will get an UnsupportedOperationException
Example – Creates a new instance of the List interface.
List<String> list = List.of("apple", "banana", "cherry"); list.set(0, "orange"); // Throws UnsupportedOperationException
2. Null Element –
Arrays.asList Allow null Element
Example –
String[] array = {"apple", null, "cherry"}; List<String> list = Arrays.asList(array); // Allowed
List.of does not Allow Null Element
Example –
List<String> list = List.of("apple", null, "cherry"); // Throws NullPointerException