Top "Unmodifiable" questions

Unmodifiable List in java

I'm trying to set a List unmodifiable. In my code, I have a method which returns a list. This list …

java list arraylist unmodifiable
What does Collections.unmodifiableSet() do in Java?

I can see that Collections.unmodifiableSet returns an unmodifiable view of the given set but I don't understand why we …

java final unmodifiable
Collections.unmodifiableList and defensive copy

If I write List<Integer> a1 = Arrays.asList(1, 2, 3); List<Integer> a2 = Collections.unmodifiableList(a1); a2 is …

java collections unmodifiable
When is the unmodifiablemap (really) necessary?

I have a map of constants, like this: private static Map<String, Character> _typesMap = new HashMap<String, …

java collections unmodifiable
Returning an unmodifiable map

Using Collections.unmodifiableMap(...), I'm trying to return an unmodifiable view of a map. Let's say I have the following method, …

java collections map unmodifiable
Java unmodifiable array

final Integer[] arr={1,2,3}; arr[0]=3; System.out.println(Arrays.toString(arr)); I tried the above code to see whether a final …

java arrays unmodifiable
How to return a thread safe/immutable Collection in Java?

In the project I am coding, I need to return a thread safe and immutable view from a function. However, …

java list thread-safety synchronized unmodifiable
How to create a deep unmodifiable collection?

I often make a collection field unmodifiable before returning it from a getter method: private List<X> _xs; .... …

java unmodifiable