javaandroidcollectionsinitializationsparse-array

How to initialize a static SparseArray


How can I initialize a static, unmodifiable instance of android.util.SparseArray?


Solution

  • You cannot do what you are attempting to. At least, not how you are attempting to do it. There is no implementation of SparseArray that is unmodifiable.

    However, you could create one. Here's how:

    Then you have an unmodifiable SparseArray in your static variable myArray.