I need to make an ArrayList of ArrayLists thread safe. I also cannot have the client making changes to the collection. Will the unmodifiable wrapper make it thread safe or do I need two wrappers on the collection?
...
I often make a collection field unmodifiable before returning it from a getter method:
private List<X> _xs;
....
List<X> getXs(){
return Collections.unmodifiableList(_xs);
}
But I can't think of a convenient way of doing that if the X above is itself a List:
private List<List<Y>> _yLists;
.....
List<List<Y>> getYLists() {
return ...
In Java, one can use the Collections#unmodifiableList() method to create an unmodifiable list from an existing List object. Is there any counterpart in C# ? I'm new to the language and haven't been able to find anything like this in the MSDN docs.
...
How would one do this?
I have tried creating a new, empty list, then copying unmodifiable list's elements to it, but I'm getting unsupported operation error.
Any help is appreciated.
...
Here I can see that "Collections.unmodifiableSet" returns an unmodifiable view of the specified set. But I do not understand why we cannot just use final modifier to create an unmodifiable set.
In my understanding final declare a constant (i.e. something that cannot be modified). So, if a set is declared as a constant it cannot be modif...
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 array's variables can be reassigned[ans:it can be].I understand that by a final Integer[] array it means we cannot assign another instance of Integer[] apart from the one we have assigned initially.I would like...
I have a map of constants, like this:
private static Map<String, Character> _typesMap =
new HashMap<String, Character>() {
{
put ("string", 'S');
put ("normalizedString", 'N');
put ("token", 'T');
// (...)
}
Do I really need to use Collections.unmodifiableMap() to...