Recently got interest in Java and started learning it. I started using NetBeans to learn Java with the GUI design. But I suddenly struck with the conversion of Text box values to integer for calculation purposes.
Finally found these two simple codes to convert a string value to an integer value.
Integer.parseInt("String");
Integer.valueOf("String");
Initialize an integer :
int x;
Assign the string to the integer:
Lets say string value will be textFeildj1.text() (Text box value)
x = Integer.parseInt(jTextField1.getText());
or
int x;
Assign the string to the integer:
Lets say string value will be textFeildj1.text() (Text box value)
x = Integer.parseInt(jTextField1.getText());
or
x = Integer.valueOf(jTextField1.getText());
No comments:
Post a Comment