Reputation: 35
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 ???
Upvotes: 3
Views: 217
Reputation: 3531
Both from storage perspective and performance you should save only "abc";
Upvotes: 1
Reputation: 48871
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.
Upvotes: 1
Reputation: 1063
If you have to concatenate multiple strings you should use StringBuilder - http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StringBuilder.html
It's much faster then using '+' or '.concat()'
Upvotes: 0