How to convert a Java string into an integer

Source: Internet
Author: User

首先你要确定你的字符串可以转换为int类型的,比如说:String s = "123";如果String s = "abc";则转换时会报错!需要的包是<a href="https://www.baidu.com/s?wd=java.lang&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3mWTznH6LnWm3PjRvn1bL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3En1mLrjDvPjmLPWTkrHmLPHcY" target="_blank" class="baidu-highlight">java.lang</a>.*;但是这个包可以不用专门引入,系统会自动引入这个包,所以可以不写。具体方法有两种:String s="123";int i;第一种方法:i=Integer.parseInt(s);第二种方法:i=Integer.valueOf(s).intValue();

How to convert a Java string into an integer

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.