Treatment objects and
The experience of converting to each other.
is a use
Written for handling
The class library of
format data is very fast. At present, it is widely used, and it has gradually replaced
If you introduce it directly
package, you can access this address download
Construct a project and add the following dependence
No code and no truth. For the simplest explanation, I directly apply the code.
This is the auxiliary settings and control the formatting output.
method is now marked as
, so please use the above method to deal with it.
There are many other setting items in the enumeration, such as the date, such as
Do not output
value and so on. Others are:
Let’s take a look at the output results. After the two conversion, the printed string should be the same:
, really the result is the same, everyone should use now
The conversion of each other, right? Well, consider another situation now, if you want to
string reverses into generics, what should I do?
Think of this:
? This is wrong, the parameter here is
Object. As shown above
Class. Therefore, if you want to get a generic collection type, you need to pass other methods:
, add twice to it
, first call
, then call
Method, this can not only convert generics
, can also be used for other sets, such as
and so on.
List<User> list =
Let the object and
Convert each other, other than that
These two categories, they can process serialization and derivativeization of fine granularity. transfer
will eventually be left to
To deal with it, if you have any doubt about this, you can see the source code of these two methods.
This article is original. If you want to reprint, please indicate the source.