I need to convert mutable list object to immutable list. What is the possible way in java?
public void action() { List<MutableClass> mutableList = Arrays.asList(new MutableClass("san", "UK", 21), new MutableClass("peter", "US", 34)); List<MutableClass> immutableList = immutateList(mutableList); } public List<MutableClass> immutateList(List<MutableClass> mutableList){ //some code here to make this beanList immutable //ie. objects and size of beanList should not be change. //ie. we cant add new object here. //ie. we cant remove or change existing one. } MutableClass
final class MutableClass { final String name; final String address; final int age; MutableClass(String name, String address, int age) { this.name = name; this.address = address; this.age = age; } }