I currently have a giant method returning a string based on a given integer. It uses a switch
statement with 686 cases, each case
returning a string constant
. There are 683 unique strings of lengths ranging from 10 to 50 characters approximately, all used inside that method only. I would like to know when these strings get loaded. Do they get loaded at class load time? If so, is there a way I could load these strings only when I first need them, and get garbaged when there are no more references?
For now, I am currently loading those strings from a file containing a table of strings. They are to be placed in a WeakHashMap. Is there a better way of doing these?
Another alternative I am thinking of is to make a class holding each string in a static field. That way, it will only be loaded the first time I fetch the field's value. But that would make my package huge.
Also, does dalvik-vm uses the same string constant loading routine.