Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance at working with strings android

Could somebody tell me what is better in terms of performance?

Is it better to save 2 strings at string.xml, like 'abc' and 'abc:'

Or should I save only the first one and concatenate ':' when needed at Java coding ???

like image 983
MSerra Avatar asked Dec 30 '25 06:12

MSerra


2 Answers

Very difficult to answer depending on what your strings will represent and what you need to append. Localization is also an issue, for example...

Dog // English
Chien // French
Hund // German

Using string resources allows you to create different resource files depending on the locale of the device and Android will automatically use the right localized string resource file. If all you need to do is append a single character such as : then you'll double every string for every language.

If you choose to only save the basic strings and append the character using code, then the code will be universal and you'll simply need to append the character to whatever localized word - potentially a lot more efficient.

like image 122
Squonk Avatar answered Dec 31 '25 22:12

Squonk


Both from storage perspective and performance you should save only "abc";

  • getting extra data from disk takes far longer as some quick in-memory actions.
  • storing the same data twice is bad practice in general
like image 28
IvoTops Avatar answered Dec 31 '25 22:12

IvoTops