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 ();