Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert int data into String data
How to convert int data into String data
Method 1:

int I = 10;

String s = ""+i;

This is a transformation by using the toString mechanism of java. When any type adds a String, it will be converted to a String first.

Method 2:

int I = 10;

string s = string . value of(I);

This is a transformation using the factory method provided by the String class.

1 、) String s = String . value of(I); ?

2 、) String s = integer . tostring(I); ?

3. The string S = ""+i;

Extended data

Because the String class is an immutable object, it can be reused at will without any problems.

In fact, there is a buffer pool of string objects inside the system. When using the String.valueOf method, it will be exhausted.

Eligible objects can be extracted from this pool.

What needs to be clear is that String is a reference type and int is a basic type, so the conversion between them is not a conversion between basic types, which is also the significance of this problem. SUN company provides the corresponding class library for programmers to use directly.