Search code examples
javastringintgettext

textField.getText() can only take Strings, what if I want it to take an int?


I have a problem. I have an UI which contains several textfields in which you are suppose to enter random characters/numbers/letters.

 String socSecNbr = textFieldCustomerSocSecNbr.getText();

In this case, of course, I want to change the socSecNbr to an int. But then the method getText() does not work.

What do I have to change it to? I tried the following code, but it still doesn't work:

 int socSecNbr = textFieldCustomerSocSecNbr.getInstance();

Thanks for the help!


Solution

  • In java you can do this:

      int value =  Integer.valueOf(textFieldCustomerSocSecNbr.getText());