Advertisement
Guest User

UnmodifiableLists

a guest
Apr 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. package functional;
  2.  
  3. import java.util.Collections;
  4. import java.util.List;
  5.  
  6. public class UnmodifiableLists {
  7.  
  8.     public static void main(String[] args) {
  9.         List<String> modifiableList = List.of("A", "B", "C");
  10.         modifiableList.add("D"); //UnsupportedOperationException
  11.         List<String> unmodifiableList = Collections.unmodifiableList(modifiableList);
  12.         unmodifiableList.add("D"); // UnsupportedOperationException
  13.         modifiableList.add("D"); //UnsupportedOperationException
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement