Creating java.util.Map in Android
I want to create a java.util.map in android from a resource. I want to do this because I have a lot of entries to populate into the java.util.map and I want to store the values in the res folder of the project in xml format.
Is there an effecient way to do this in android? My map will have around 2500 entries so I want to do this as effeciently as possible and I don't want to hard code them...
Thanks, Gaz
Asked by: Maddie279 | Posted: 20-01-2022
Answer 1
I think the Xml format is "too much" to simply store key-value pairs. A text file where a line is a key-value pair is more adequat (e.g. with comma separator), also the parsing will be easier.
foo1,bar1
foo2,bar2
...
- Save your text file in
res/raw
directory - Open it via
context.getResources.openRawResource(R.raw.fileName)
- Loop on each lines and split the line to retrieve the key and the value.
- Put them in your map
That's all
Answered by: Alfred636 | Posted: 21-02-2022Similar questions
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android