Use of string. valueof () method

Source: Internet
Author: User

1. Convert from basic data type to string

The string type provides the static method to convert the basic data type to the string type.
That is, the multiload method of the string. valueof () parameter.
There are several
String. valueof (Boolean B): Convert Boolean variable B to a string
String. valueof (char C): Convert char variable C to string
String. valueof (char [] data): converts the char array data to a string.
String. valueof (char [] data, int offset, int count ):
Convert count elements from data [offset] In char array data into strings
String. valueof (double D): Convert double variable d to string
String. valueof (float F): converts the float variable F to a string.
String. valueof (int I): converts int variable I to a string
String. valueof (long l): converts long variable L to a string
String. valueof (Object OBJ): converts an OBJ object to a string, which is equal to OBJ. tostring ()
Usage example:
Int I = 10;
String STR = string. valueof (I );
At this time, STR will be "10"
2. Convert string to the basic data type of a number
Convert string to basic data type
Most of the packages that require basic data types
For example, convert string to byte
You can use byte. parsebyte (string S)
If this method cannot analyze s, numberformatexception is thrown.
Byte:
Byte. parsebyte (string S): converts s to byte
Byte. parsebyte (string S, int Radix): converts s to byte Based on Radix.
For example, byte. parsebyte ("11", 16) will get 17
Double:
Double. parsedouble (string S): Convert s to double
Float:
Double. parsefloat (string S): converts s to float
INT:
Integer. parseint (string S): converts s to int
Long:
Long. parselong (string

 

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.