0

I have the array in Arrays.xml

<string-array name="text_language">
    <item> English</item>
    <item> Russian</item>
</string-array>

How can I check, array contain the string (for example from EditText)?

Maybe,

 if(getResources().getStringArray(R.array.text_language).contains(" "));

does not work.

Daniel
  • 4,033
  • 4
  • 24
  • 33

2 Answers2

0

Below code works perfect:

String[] myArray = getResources().getStringArray(R.array.array);
List<String> mList = Arrays.asList(myArray );
if(mList .contains("your_value")){
   System.out.println("String Exists");
}
Girish Arora
  • 966
  • 6
  • 7
0

Same as MeosCoder, but here .equals() instead of contains()

As contains() will return a part of matched string, we should .equals() to properly find the data whether its available or not.

String[] array = getResources().getStringArray(R.array.yourarray);
for (String data: array) {
    if (data.equals(your_data)) {
        //data is there
    }else{
        //your_data is not in array
    }
}
Ranjit
  • 5,130
  • 3
  • 30
  • 66