Common Data Transformation in Java)

Source: Internet
Author: User

1.int --> short

Exp: Short callback Var = 0;


Int intvar = 0;


Using VaR = (short) intvar

2. Short --> int



Exp: Short callback Var = 0;


Int intvar = 0;


Intvar = callback var;

3. Int-> string


Exp: int intvar = 1;


String stringvar;


Stringvar = string. valueof (intvar );

4. Float-> string


Exp: Float floatvar = 9.99f;


String stringvar;


Stringvar = string. valueof (floatvar );

5. Double-> string


Exp double doublevar = 99999999.99;


String stringvar;


Stringvar = string. valueof (doublevar );

6. Char-> string


Exp char charvar = 'a ';


String stringvar;


Stringvar = string. valueof (charvar );

7 string-> int, float, long, double


Exp string intstring = "10 ";


String floatstring = "10.1f ";


String longstring = "99999999 ";


String doublestring = "99999999.9 ";

Int I = integer. parseint (intstring );


Float F = integer. parseint (floatstring );


Long Lo = long. parseint (longstring );


Double D = double. parseint (doublestring );

8 string-> byte, short


Exp string S = "0 ";


Byte B = integer. intvalue (s );


Short SH = integer. intvalue (s );

9 string-> char


Exp string S = "ABC ";


Char A = S. charat (0 );


Return character

10 string --> Boolean


String S = "true ";


Boolean flag = Boolean. valueof ("S ");

Long --> int, int --> long

This basic type can be forcibly converted.

Int I = 1;

Long L = (long) I;

Double D = (double) I;

Date (date) ------------> string (character)

Date d = new date ();

String Ss = D. tolocalestring ();

Or

Simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");

String Ss = format (d );




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.