Conversions between string, Integer, int in Java data type

Source: Internet
Author: User

Turn from:

Http://www.blogjava.net/ljc-java/archive/2011/02/28/345344.html

1.Integer Convert to int method

Integer i = new Integer (10);
int k = I.intvalue ();
namely Integer.intvalue ();

2.int Convert to Integer

int i = 10;

Integer it = new Integer (i);

3.String Convert to int method

String str = "10";
Integer it = new Interger (str);

int i = It.intvalue ();

That is: int i = Integer.intvalue (string);

4.int Conversion to String

int i = 10;

(1) String s = string.valueof (i);

(2) String s = ingeger.tostring (i);

(3) String s = "" + I;

5.String Convert to Integer

String str = "10";

Integer it = integer.valueof (str);

6.Integer Conversion to String

Integer it = new Integer (10);

String str = it.tostring ();

7.String conversion 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);

Get today's date string
String today = java.text.DateFormat.getDateInstance (). Format (new java.util.Date ());
Get today's date
New Java.sql.Date (System.currenttimemillis ());

Conversions between string, Integer, int in Java data type

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.