I would prefer getting the size of set and compare with size of list to know if there are any duplicates. List.of() 1. List numbers = List.of(1,2,3); this code is okay, however List numbers = List.of(1,2,3, null); results in nullpointerexception 2. List numbers = List.of(1,2,3); numbers.add(4); this results in unsupportedoperationexception 3. List numbers = List.of() generates an empty list List.of() 1. List numbers = List.copyOf(List.of(1,2,3)); this code is okay, however List numbers = List.of(1,2,3, null); results in nullpointerexception 2. List numbers = List.copyOf(List.of(1,2,3)); numbers.add(4); this results in unsupportedoperationexception 3. List numbers = List.copyOf(List.of()) generates an empty list
1. Use Set.of and/or Set.copyOf
2. This will throw if the list has duplicate elements.
I would prefer getting the size of set and compare with size of list to know if there are any duplicates.
List.of()
1. List numbers = List.of(1,2,3); this code is okay, however List numbers = List.of(1,2,3, null); results in nullpointerexception
2. List numbers = List.of(1,2,3); numbers.add(4); this results in unsupportedoperationexception
3. List numbers = List.of() generates an empty list
List.of()
1. List numbers = List.copyOf(List.of(1,2,3)); this code is okay, however List numbers = List.of(1,2,3, null); results in nullpointerexception
2. List numbers = List.copyOf(List.of(1,2,3)); numbers.add(4); this results in unsupportedoperationexception
3. List numbers = List.copyOf(List.of()) generates an empty list
@@The1080Pi How is any of this relevant to what I said?
Correct