Skip to content
Advertisement

Immutable array in Java

Is there an immutable alternative to the primitive arrays in Java? Making a primitive array final doesn’t actually prevent one from doing something like

JavaScript

I want the elements of the array to be unchangeable.

Advertisement

Answer

Not with primitive arrays. You’ll need to use a List or some other data structure:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement