Conversion between string, integer, and INT in Java Data Types

Source: Internet
Author: User

Conversion between string, integer, and INT in Java Data Types

 

These conversions often make me dizzy. I simply found an article, which is quite clear at first glance. By the way, the article comes from:
Http://blog.sina.com.cn/cnxiaotao

1. Integer Conversion to int

Integer I;
Int K = I. intvalue ();
That is, integer. intvalue ();

 

2.int to integer

Int I;

Integer it = new INTEGER (I );

 

3. Convert string to int

String STR = "10 "; 
IntegerIt = newInterger (STR ); 

IntI = it. intvalue (); 

That is, intI = integer. intvalue (string );

 

4.int to string

Int I;

(1) string S = string. valueof (I );

(2) string S = ingeger. tostring (I );

(3) string S = "" + I;

 

5. Convert string to integer

String STR = "10"

Integer it = integer. valueof (STR );

 

6. Convert integer to string

Integer it;

String Str= It. tostring ();

 

7. Convert string to bigdecimal

Bigdecimal BD = new bigdecimal (STR );

 

8. Date

Calendar calendar = calendar. getinstance ();
Int year = calendar. Get (calendar. year );
Int month = calendar. Get (calendar. month) + 1;
Int day = calendar. Get (calendar. date );

// Obtain the date string of today
String today = java. Text. dateformat. getdateinstance (). Format (New java. util. Date ());
// Obtain the date of today
New java. SQL. Date (system. currenttimemillis ());






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.