123456789101112131415



Question 1: How do you get immutable object of a collection ? For example if you were to write an API which return a List or a Set or a Map when a method is called, but you also want that you don´t want the client of your API to add or delete any object in the returned collection ?
1. Use Collections.immutableCollection() method.
2. Use the Collections.unmodifiableXxxx() method with the collection as an argument,which returns an immutable object of specific type.