JAVA basics: interchange between numeric variables and strings in java

Source: Internet
Author: User
JAVA basics: interchange of numeric variables and strings in java-Linux general technology-Linux programming and kernel information. For details, see below. The conversion between numeric variables and string variables in java is divided into explicit and implicit conversions. Implicit conversions are automatically converted where the system deems that the conversion is required, for example:
Int I = 65;
System. out. println ("value of I is:" + I );
The screen will output: value of I is 65. At this time, the system implicitly converts int type I to String type and then connects it with the previous String.

In many cases, we need to forcibly convert numeric and string variables by using the following method:
1. Convert string to numeric value
(1) convert a string to an integer
Public static int parseInt (String s, int radix) // the String to be converted. radix indicates the conversion in hexadecimal notation. For example, 10 indicates decimal notation, 16 is hexadecimal.
(2) converting a string to a floating point number
Public static float parseFloat (String s) // s is the String to be converted
2. Convert numeric values to strings
Public static String valueOf (Object obj) // obj can be any type of numeric variable.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.