Parameter between string and basic information type

Source: Internet
Author: User
1. The string type is converted from the basic information category.

The static method for converting basic data types into strings is provided in the string type.
That is, the method of string. valueof ().

There are the following types

String. valueof (Boolean B): converts Boolean to B into a string.

String. valueof (char C): converts a char to a string.

String. valueof (char [] data): Convert the data of the char character column into a string

String. valueof (char [] data, int offset, int count ):
Starting from data [offset] In the char primary column data, take count elements into strings.

String. valueof (double D): converts double into a string.

String. valueof (float F): converts a float value to a string.

String. valueof (int I): converts int into a string.

String. valueof (long l): converts long numbers into strings.

String. valueof (Object OBJ): convert an OBJ object into a string, such as obj. tostring ()

Usage example:
Int I = 10;
String STR = string. valueof (I );
At this time, STR will be "10"

2. Basic data types converted from string indexes to numbers

To convert string indexes into basic information indexes
Most package Types that require basic information

For example, string bytes are converted into bytes.
You can use byte. parsebyte (string S)
If this method cannot analyze s, numberformatexception will occur.

Byte:
Byte. parsebyte (string S): Convert s bytes to byte
Byte. parsebyte (string S, int Radix): Base Radix to convert s bytes to byte
For example, byte. parsebyte ("11", 16) will get 17

Double:
Double. parsedouble (string S): Convert s into double

Float:
Double. parsefloat (string S): Convert s into float

INT:
Integer. parseint (string S): Convert s into int

Long:
Long. parselong (string S): Convert s into long

Usage example:

try
{
String str = "1234";
int a = Integer.parseInt(str);
}
catch (NumberFormatException e)
{
System.out.println(" parse int error!! " + e);
}

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.