-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-09-02 17:11:30.186703 new snippets
- Loading branch information
1 parent
be37b8c
commit 029b186
Showing
34 changed files
with
459 additions
and
2,028 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//date: 2024-09-02T16:44:47Z | ||
//url: https://api.github.com/gists/80bdaec048a85c75aea97e18c2230ce9 | ||
//owner: https://api.github.com/users/cyurtoz | ||
|
||
// Creating a mutable ArrayList | ||
List<Integer> originalList = new ArrayList<>(); | ||
originalList.add(1); | ||
originalList.add(2); | ||
|
||
// Creating an unmodifiableList on top of the mutable ArrayList | ||
List<Integer> unmodifiableList = Collections.unmodifiableList(originalList); | ||
System.out.println(unmodifiableList); // prints [1, 2] | ||
|
||
unmodifiableList.add(3); // throws java.lang.UnsupportedOperationException | ||
|
||
// add 3 to underlying list | ||
originalList.add(3); | ||
System.out.println(unmodifiableList); // prints [1, 2, 3] | ||
// data on unmodifiableList has changed |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.