-2

I have two array lists, one list is of strings and second of Toggle button.Now I want to compare the strings in two arrays.Please help me.

for(int i=0; i<arrayList1.size();i++){
            for (int j=0; j<arrayList.size();j++){

                Log.d("error in response:  ", "  " + arrayList.get(j).getText());

                Log.d("Tag" , arrayList1.get(i));
                if(arrayList1.get(i)==arrayList.get(j).getText()){

                    Log.d("Tag" , arrayList1.get(i));
                    Log.d("Tag" , String.valueOf(arrayList.get(j).getText()));

                    onCheckedChanged(arrayList.get(j), true);
                }
            }
        }
dhananjay sharma
  • 17
  • 1
  • 1
  • 5

2 Answers2

0

You have to use String#equals, because == used on objects checks if they're the same instance.

Gabriel B.
  • 46
  • 1
  • 6
0

You can do by foreach loop too or just compare string by equals method call:

for(String textString1:arrayList1 )
        {
            for(String textString:arrayList )
            {
                if(textString1.equalsIgnoreCase(textString))
                {
                    //do your stuff
                }
            }
        }