lundi 5 juin 2017

Validation of input data via Scanner

I have a problem with if-statement. There is a file with the line admin.admin. I break the line into points and store it in an array. The first element of the array is the login. The first element of the array is compared with the input value (inputLogin = "admin" in the code String inputLogin = textField[0].getText()). I have to get the true, but I'm actually getting a false

                    scanner = new Scanner(file);
                    String account = scanner.nextLine();
                    String[] parts = account.split("\\.");
                    String login = parts[0];
                    String inputLogin = textField[0].getText();

                    if (inputLogin.equals(login) == true) {
                         System.out.println("Good!");
                    }
                    else {
                         System.out.println("Very BAD");
                    }

Aucun commentaire:

Enregistrer un commentaire