Java If Statement having multiple conditions with && operator not working

Mohit :

private void validate(String userName, String userPassword){
        if((userName == "Admin") && (userPassword == "1234")){
            Intent intent = new Intent(MainActivity.this, SecondActivity.class);
            startActivity(intent);
        } else{
            counter --;
            Info.setText(userName + " Number of Attempts Left: "+String.valueOf(counter) + " - " + userPassword);
            if(counter == 0){
                Login.setEnabled(false);
            }
        }
    }

Whenever i give input as "Admin" and "1234" condition goes to else part. please help me i am beginner in this field.

IntelliJ Amiya :

string equals() method compares the two given strings based on the data/content of the string.

Try with

  if(userName.equals("Admin") && userPassword.equals("1234")){
            Intent intent = new Intent(MainActivity.this, SecondActivity.class);
            startActivity(intent);
        } else{
            counter --;
            Info.setText(userName + " Number of Attempts Left: "+String.valueOf(counter) + " - " + userPassword);
            if(counter == 0){
                Login.setEnabled(false);
            }
        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=183078&siteId=1