A method of converting between several common data types in Java

Source: Internet
Author: User

Conversion methods for several commonly used data types in Java:

1. Short-->int Conversion

Exp:short shortvar=0;

int intvar=0;

Shortvar= (short) Intvar

2. Int-->short Conversion

Exp:short shortvar=0;

int intvar=0;

Intvar=shortvar;

3. int->string Conversion

Exp:int intvar=1;

String Stringvar;

Stringvar=string.valueof (Intvar);

4. float->string Conversion

Exp:float floatvar=9.99f;

String Stringvar;

Stringvar=string.valueof (Floatvar);

5. double->string Conversion

Exp double doublevar=99999999.99;

String Stringvar;

Stringvar=string.valueof (Doublevar);

6. char->string Conversion

Exp Char charvar= ' a ';

String Stringvar;

Stringvar=string.valueof (Charvar);

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.