Basic knowledge of Java-conversion of basic data types, strings, and byte Arrays

Source: Internet
Author: User

Basic knowledge of Java-conversion of basic data types, strings, and byte Arrays

Author: Chen yuefeng

From: http://blog.csdn.net/mailbomb

 

In a program, conversion between basic data types, strings, and byte arrays is often required. Below are some common conversion methods:

1. Convert the basic data type to a string

Use the valueof method in the string class.

For example:

Int I = 10;

String S1 = string. valueof (I );

Other basic data types are the same as the conversion.

2. convert a string to a basic data type

String S =" 1234" ;

Int I = integer. parseint (s );

Others are similar to this.

3. Convert the basic data type to a byte array

You can first convert the basic data type to a string and then convert it to a byte array, so that there is no Chinese problem.

Int I = 100;

String S = string. valueof (I );

Byte [] B = S. getbytes ();

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.