Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is better to use, hardcoded array or resources string array?

Tags:

java

android

What is better to use in my android program:

in mainActivity.java:

String[] st = {"Value1","Value2"}; 

or

in mainActivity.java:

String[] st = (String[]) getResources().getStringArray(R.array.Array1); 

And in strings.xml:

<string-array name="Array1">
    <item >Value1</item>
    <item >Value2</item>
</string-array>
like image 692
Anton Baryshnikov Avatar asked Jun 04 '12 07:06

Anton Baryshnikov


People also ask

What is a hardcoded string?

The term hardcoded string refers to a string that doesn't depend on the input to the program but it also has connotations of being hard to change, meaning that you might have to edit the code in one or more places to change it.

Can arrays use strings as elements?

In one of our previous tutorials, we have discussed the various types of data that an Array can hold. One of the data types that arrays can hold is a string. In this case, the array is called a String array.

Can you make an array of strings in C++?

Thus, C++ Vectors can be used to create a string array and manipulate the same easily. The vector. push_back(element) method is used to add elements to the vector string array.


1 Answers

Well I will use the second approch, if you need to localize (translate it in more languages) your strings.

like image 76
Blackbelt Avatar answered Sep 27 '22 22:09

Blackbelt