Two String variables of equal value are not comparing to be equal (android)

I have two variables, one is a String array that is filled from a database, and the other is generated in the program, and I want to execute code if they are equal. I have verified that they have the same value, but the comparison seems to fail.

In this case, the element of the String array is also equal to "2", but the comparison fails.

if (r3.isChecked())
     {
          choosenButton = "2";
          if (choosenButton == Global.dbCorrectAnswer[0])
          {
             Toast.makeText(MySchoolOnline.this, "Correct", Toast.LENGTH_SHORT).show();

          }
      }

Answers


You should use equals to compare the variables:

choosenButton.equals(Global.dbCorrectAnswer[0])

Need Your Help

Low priority job in node.js

javascript multithreading node.js

Based on the fact that node uses a single thread to manage everything, I am curious how I should go about handling a low-priority job

Finding minimum difference between fit line and data points in R

r intersection minimum

Currently, I am trying to find a way to write a function in R that will find the yield strength of a material from a stress strain curve. I have 24 stress strain plots of specimen that were tensile