Conversion of common data types in Java

Source: Internet
Author: User
1. Common data type conversion functions in Java
String-& gt; byte
Byte static byte parsebyte (string S)
Byte-& gt; string
Byte static string tostring (byte B)
Char-& gt; string
Character static string to string (char C)
String-& gt; short
Short static short parseshort (string S)
Short-& gt; string
Short static string tostring (short S)
String-& gt; integer
Integer static int parseint (string S)
Integer-& gt; string
Integer static string tostring (int I)
String-& gt; long
Long static long parselong (string S)
Long-& gt; string
Long static string tostring (long I)
String-& gt; float
Float static float parsefloat (string S)
Float-& gt; string
Float static string tostring (float F)
String-& gt; double
Double static double parsedouble (string S)
Double-& gt; string
Double static string tostring (double D)
2. Data type conversion of Classes
// Convert string to int
Public static int stringtoint (string intstr)
{
Integer integer;
Integer = integer. valueof (intstr );
Return integer. intvalue ();
}
// Convert int to string
Public static string inttostring (INT value)
{
Integer integer = new INTEGER (value );
Return integer. tostring ();
}
// Convert string to float
Public static float stringtofloat (string floatstr)
{
Float floatee;
Floatee = float. valueof (floatstr );
Return floatee. floatvalue ();
}
// Convert float to string
Public static string floattostring (float value)
{
Float floatee = new float (value );
Return floatee. tostring ();
}
// Change the string type to the sqldate type
Public static java. SQL. Date stringtodate (string datestr)
{
Return java. SQL. Date. valueof (datestr );
}
// Change the sqldate type to the string type
Public static string datetostring (Java. SQL. Date datee)
{
Return datee. tostring ();
}
--

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.