Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point {
- public int x,y;
- public Point(int x, int y) {this.x = x;this.y = y;}
- @Override
- public String toString() {
- return "Point{" +
- "x=" + x +
- ", y=" + y +
- '}';
- }
- }
- // Testing ---------------------------------------------
- List<Point> list = new ArrayList<>();
- // populate the list
- list.add(new Point(1,2));
- // printing the list
- System.out.println("Initial list: " + list);
- // getting unmodifiable list
- List<Point> immutableList = Collections.unmodifiableList(list);
- Point p = immutableList.get(0);
- p.x = 10;
- // printing the list
- System.out.println("immutableList: " + immutableList.toString());
- // RESULT:
- Initial list: [Point{x=1, y=2}]
- immutableList: [Point{x=10, y=2}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement