1. Convert string to integer (String--->int)
Method 1:
(1) int i = Integer.parseInt(String s);
Among them (1) is actually what we often use to convert s into decimal numbers. In fact, the default is to call int i =Integer.parseInt("123", 10);
(2) i = Integer.parseInt(String s,int radix);
The range of radix is between 2 and 36, and an exception will be thrown outside the range. The length of s cannot exceed 7, otherwise an exception will be thrown.
Method 2:
int i = Integer.valueOf(my_str).intValue();
Note: The method of converting a string to Double, Float, and Long is similar to the above.
2. How to convert integers into strings (int--->String)
(1) String s = String.valueOf(i);
(2) String s = Integer.toString(i);
(3) String s = "" + i;
Note: The method of converting Double, Float, Long to string is similar to the above.
The above is the relevant knowledge about commonly used type conversion (recommended) in Java introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!