Java-Conversions between basic data types

Source: Internet
Author: User

 Public classchangetype { Public Static voidMain (string[] args) {String ar= "true";//string to Boolean, as long as it is not "true" and the result is false;        BooleanAR1 =Boolean.parseboolean (AR); if(AR1) {System.out.println ("true");//the result is true;} String Str= "12";//String Goto int        intm =integer.parseint (str);                System.out.println (m); String STR0= "12.6";//convert string to double        Doublex =double.parsedouble (STR0);                SYSTEM.OUT.PRINTLN (x); inty = 5; String str1= y+ "";                System.out.println (STR1); intflag = 100;//int to string, any type connected to a string becomes a string type. Not recommended for useString a = flag+ "";                 System.out.println (a); intFLAG0 = 200;//int to string using string.valueof ();String STR3 =string.valueof (FLAG0);                System.out.println (STR3); floath = 12.6f;//float to int, from high to low must be forced type conversion, loss precision changed to        intW = (int) H;    System.out.println (w); //The result is                floatc = 89.6666f; Doubles =C;    System.out.println (s); //The result is 89.666677987979                DoubleE = 78.999999999; floato = (float) E;   System.out.println (o); //The result is                                     }}

Java-Conversions between basic data types

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.