Explanation of the String.valueof () method in Java

Source: Internet
Author: User

1. Conversion from basic data type to String
The static method for converting basic data types to string has been provided in the string category
That is, the string.valueof () is a method of multi-load parameter
Have the following types of
String.valueof (Boolean B): Converts a Boolean variable B to a string
String.valueof (char c): convert char variable C to string
String.valueof (char[] data): Converting char array data to a string
String.valueof (char[] data, int offset, int count):
Converts the char array data from Data[offset] to count elements to a string
String.valueof (double D): Converts a double variable d to a string
String.valueof (float f): Convert float variable F to string
string.valueof (int i): convert int variable i to string
String.valueof (Long L): convert long variable L to string
String.valueof (Object obj): Converts the Obj object to a string, equal to Obj.tostring ()
Usage such as:
int i = 10;
String str = string.valueof (i);
This time, STR will be "10."
2. Basic data type converted from String to digital
To convert a String to the basic data type, go
Most of the packaging categories that need to use basic data types
such as String conversion to byte
You can use Byte.parsebyte (String s)
This type of method will be thrown out if s analysis is not possible numberformatexception
BYTE:
Byte.parsebyte (String s): convert S to byte
Byte.parsebyte (String s, int radix): Converts S to byte with Radix as base
Say Byte.parsebyte ("11", 16) will get 17
Double:
Double.parsedouble (String s): converts S to double
float:
Double.parsefloat (String s): convert S to float
Int:
Integer.parseint (String s): convert s to int
Long:
Long.parselong (String s): convert S to Long

Explanation of the String.valueof () method in Java

Related Article

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.