Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package functional;
- import java.util.Collections;
- import java.util.List;
- public class UnmodifiableLists {
- public static void main(String[] args) {
- List<String> modifiableList = List.of("A", "B", "C");
- modifiableList.add("D"); //UnsupportedOperationException
- List<String> unmodifiableList = Collections.unmodifiableList(modifiableList);
- unmodifiableList.add("D"); // UnsupportedOperationException
- modifiableList.add("D"); //UnsupportedOperationException
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement