Data type conversions for Java basics

Source: Internet
Author: User

A basic type of mutual transfer

1.String with other base types (here common base types and corresponding wrapper classes are replaced with type, type)

A. Turn string:string. ValueOf (base variable)

B. String to base class: Type.valueof (string variable) return type is wrapper class

            parseType (string variable) return types are the underlying type

    

  2. Conversion of the underlying types to each other

General idea: Now convert it to a string and then to the desired type.

Two JSON format string to Bean

  1. Transfer through Gson

    Gson Gson = new Gson ();

Bean bean = Gson.fromjson (jsondata,bean. Class);

2. Transfer through Jsonobject

    Jsonobject Jsonbean = Jsonobject.fromobject (JSONSTR);

  Jsonobjec.tobean (Jsonbean,bean);

 

 Note : When you convert by Gson, all the double data in the JSON data is converted to type int. Method 2 does not have this disadvantage.

  

-------------not finished---------------follow up and slowly add!

Data type conversions for Java basics

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.