+ 2
Why does the else statement gets executed here?
<TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="your"/> text3 = (TextView) findViewById(R.id.text3); String c = text3.getText().toString(); String b = "your"; if(c == b) { Toast.makeText(getApplicationContext(), "SUCCESS ", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(getApplicationContext(), "Fail ", Toast.LENGTH_SHORT).show(); }
4 Antworten
+ 19
▪equals() method
== tests for reference equality,
(whether they are the same object)
.equals( ) tests for value equality,
(whether they are logically "equal")
➝ equals() is a method used to compare two objects for equality.
The default implementation of the equals() method in the Object class returns true if and only if both references are pointing to the same instance. It therefore behaves the same as comparison by == .
0
String a,b;
a = "AA";
a = a +"A"; //AAA
b = "AAA";
System.out.println( a == b ); //false
System.out.println( a.equals(b) ); //true