gudii9
asked on
collection read only
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Main {
public static void main(String[] argv)
throws Exception {
List stuff = Arrays.asList(new String[] { "a", "b" });
List list = new ArrayList(stuff);
list = Collections.unmodifiableLi st(list);
try {
list.set(0, "new value");
}
catch (UnsupportedOperationExcep tion e) {
}
Set set = new HashSet(stuff);
set = Collections.unmodifiableSe t(set);
Map map = new HashMap();
map = Collections.unmodifiableMa p(map);
System.out.println("Collec tion is read-only now.");
}
}
I was runniong above program from link
http://www.tutorialspoint.com/javaexamples/collection_readonly.htm
How do I prove to myself that callection is read only now. I want to test it.
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Main {
public static void main(String[] argv)
throws Exception {
List stuff = Arrays.asList(new String[] { "a", "b" });
List list = new ArrayList(stuff);
list = Collections.unmodifiableLi
try {
list.set(0, "new value");
}
catch (UnsupportedOperationExcep
}
Set set = new HashSet(stuff);
set = Collections.unmodifiableSe
Map map = new HashMap();
map = Collections.unmodifiableMa
System.out.println("Collec
}
}
I was runniong above program from link
http://www.tutorialspoint.com/javaexamples/collection_readonly.htm
How do I prove to myself that callection is read only now. I want to test it.
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.