In my app, the main set of data is a two-dimensional char array (char[][]), in which some of the values may be non-printable characters and even \0 characters. What would be the fastest way to store this array in the shared prefs and retrieve it later? Speed of retrieval is a lot more important to me than the speed of saving it. The arrays are not particularly large, probably no more than 100×100.
Presently, I’m converting it into a string by simply concatenating all characters, row-by-row, column-by-column, and storing the string along with the dimensions (as int).
I have also considered just serialising the array (writeObject into a ByteArrayOutputStreram and then use the stream’s toString method), but haven’t tried it yet.
Any other suggestions? Again, the fastest possible retrieval (and recreation as the char[][] array) is my primary concern.
Because
StringSetmethods (put and get) are only available from Android 3.0 and also because I found the preferences being less than reliable when storing long strings, especially those containing 0-chars, I use a different way of storing data in the app.I use internal files (
fileGetInputandfileGetOutput), I then create aHashMap<Integer, char[][]>and write it to the file usingwriteObject. As I have a few of those char arrays, identified by an integer ID, this way I’m saving them all in one go.I do realise that I may be loosing something in terms of performance, however in this case reliability comes first.