Questions tagged [unmodifiable]

67 questions
0
votes
2 answers

Can Collections.unmodifiableMap retain the original map?

I have a piece of code below: class Util { private static final Map MY_MAP; static { Map tmpMap = new TreeMap(); tmpMap.put("key1", "val1"); tmpMap.put("key2",…
injoy
  • 3,993
  • 10
  • 40
  • 69
0
votes
3 answers

Why don't the unmodifiable methods from Collections class, create collections with new elements?

Suppose there is this code: List modifiableList = new ArrayList(Arrays.asList("1","2","3")); List unmodifiableList =…
Random42
  • 8,989
  • 6
  • 55
  • 86
0
votes
2 answers

an example to illustrate this point on unmodifiableCollection in Java?

I am reading Core Java Volume I - fundamentals (9th edition) by Cay S. Horstmann and Gary Cornell. Here is a paragraph from the book which I do not understand. If you could demonstrate with a simple example what it means, it would be great.…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
0
votes
1 answer

JavaScript, defining unmodifiable Enumerations

So, I was inspired by this question ( Enums in JavaScript? ) to get to work on a library insert for JavaScript to enable unmodifiable Enumerations. I have a decently working method defined already, but I'd like to flesh it out more. This concept…
Duncan
  • 1,530
  • 15
  • 20
-1
votes
2 answers

Confusion in chossing data structure

I want to create a Map. Which is the best option for me? I tried this one private Map[]> questionIdToanswersMapping = Collections.unmodifiableMap(Stream.of( new…
user3681970
  • 1,201
  • 4
  • 19
  • 37
-1
votes
2 answers

unmodifiable Map still accept adding entries without return UnsupportedOperationException

Am trying out adding entry to unmodifiable Map, JVM catch UnsupportedOperationException when adding entry to a subview of original Map, but JVM does not care about direct adding to the original view, code speaks : ConcurrentMap
Rehme
  • 323
  • 3
  • 6
  • 20
-3
votes
1 answer

Collections.unmodifiableList wraps already unmodifiable list?

In Collections.unmodifiableList implementation I see that it always wraps the given list with UnmodifiableList even if the given list is already UnmodifiableList... So if i'm calling this method over and over - i get a huge stack trace, like this: …
duduamar
  • 3,816
  • 7
  • 35
  • 54
1 2 3 4
5