0

I tried cloning a sparse array into a temp one and the clearing the original before adding the temp SparseArray back into the original one, but because the lookup is binary that doesn't seem to work. Is there any way to accomplish this or do I need to look at alternative mapping structures? I'm storing the array into a JSON file as a JSONArray and I'm not sure how I can do that with a generic map.

The information on SparseArrays and the lookup function being a binary search is right here: https://developer.android.com/reference/android/util/SparseArray. So I am asking if it is possible to add elements to the beginning of the SparseArray rather than at the end. It doesn't seem like that may be possible, so I am wondering if there is an alternative efficient mapping structure that can be easily stored in a JSON file and allows me to add elements to the front of the data structure. Here is some example code of how I want to store the data structure:

SparseArray<String> sparse = new SparseArray<>();
//Populate list...
JSONObject ListObject = new JSONObject();
ListObject.put("ListData", sparse);

This is how I will read the data mapping structure from the JSON file (I don't believe that I can do this with a HashMap):

JSONObject temp = new JSONObject();
sparse = readJSONArray(temp.getJSONArray("ListData"));
nosh
  • 620
  • 3
  • 14
  • 50

0 Answers0