lundi 23 octobre 2017

Compare String to Arrays.asList values with if statement

I'm using FXML to create a user interface. There's a TextField which can be filled in, and a Button to be clicked.

When clicking on the button, the text that has been filled in should be read and compared to a List.

If the TextField contains characters that are equal to a value in the List, then a certain String should be displayed in a Text field on the same user interface.

public class FXMLController {

      @FXML TextField input
      @FXML private Text actionContains

      @FXML protected void handleSubmitButtonAction(ActionEvent event) {

             List<String> n1 = Arrays.asList("44606", "44613", "44615", "44619"}

             String getInput = input.getText();

             if(Arrays.asList(n1).contains(getInput)) {
                  actionContains.setText("CONTAINS");
             } else {
                  actionContains.setText("DOES NOT CONTAIN");
             }
     }
}

It's not a problem to run the code. The String getInput's value equels the input text, but the result of the if statement is always "DOES NOT CONTAIN". The entered text is for example "44606621".

I've already cut off the last three characters in order to have a String which is equal or not to a List value (so equals in stead of contains), but this does nothing to the result.

Aucun commentaire:

Enregistrer un commentaire