Exchange

If Condition Between Two Strings in Android Studio

To check if a condition is true between two strings in Android Studio, you can use the equals() or equalsIgnoreCase() method. Here's an example code snippet:

String string1 = "Hello"; String string2 = "hello"; if(string1.equals(string2)){ // Condition is true Log.d("TAG", "Strings are equal"); } else { // Condition is false Log.d("TAG", "Strings are not equal"); }

In this example, the equals() method is used to check if string1 and string2 are equal. The equalsIgnoreCase() method can be used instead of equals() if you want to ignore case sensitivity.


another example

Wrong

 


status = snapshot.child("Status").getValue().toString();

String x = "Pending";

if (status == x){
Toast.makeText(HomeActivity.this, "Pending Order", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(HomeActivity.this, status, Toast.LENGTH_SHORT).show();
}


Wright 


status = snapshot.child("Status").getValue().toString();

//String x = "Pending";

if (status.equals("Pending")){
Toast.makeText(HomeActivity.this, "Pending Order", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(HomeActivity.this, status, Toast.LENGTH_SHORT).show();
}





Post a Comment

0 Comments