How to Check if String Array Contains a Specific String in Android

Here is how to get a specific value or String from Array in Android

To check if a string array contains a specific string, you can use this code, this is a simple code and very useful

First, let’s create a string array

String[] myStrings={
            "john",
         "James",
            "beeran",
   
   };

So we created a string array called “myStrings”. Now let’s find if we can get a specific string from it.

 if (Arrays.asList(myString).contains("beeran")){
 Toast.makeText(mContext, "succcess", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mContext, "fail", Toast.LENGTH_SHORT).show();
}

This is it.

If you need any help related to android development, create android apps, fix issues in your android projects etc, you can contact me

Post navigation

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.