惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
V
V2EX
GbyAI
GbyAI
量子位
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
O
OpenAI News
N
News and Events Feed by Topic
博客园 - Franky
爱范儿
爱范儿
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
Last Week in AI
Last Week in AI
罗磊的独立博客
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
J
Java Code Geeks
I
Intezer

博客园 - powerlx

CSS3手风琴菜单 下拉展开带弹性动画 Java中用Apache POI生成excel和word文档 java 对EXCEL表格的操作。包括EXCEL 2007 include 问题 数字显示科学计数法的问题 java如何提取url里的域名 AS快捷键 Java三大主流框架概述 java.lang.ArrayIndexOutOfBoundsException: 1 java 对EXCEL表格的处理 JAVA下载文件中文乱码问题 Java 判断文件夹、文件是否存在、否则创建文件夹 jspSmartUpload上传下载全攻略 intellJ实用技巧 main 方法, 老师,有没有类似微信布局的好的开源库? Android 日常开发总结的技术经验 60 条 新的android studio创建的fragment工程跟老师讲的结构有区别 默认情况下优先级应该是谁先注册谁的优先级就高吧?
Java 如何将String转化为Int
powerlx · 2016-12-15 · via 博客园 - powerlx

在 Java 中要将 String 类型转化为 int 类型时,需要使用 Integer 类中的 parseInt() 方法或者 valueOf() 方法进行转换.

例1:

1

2

3

4

5

6

String str = "123";

try {

    int a = Integer.parseInt(str);

catch (NumberFormatException e) {

    e.printStackTrace();

}

例2:

1

2

3

4

5

6

String str = "123";

try {

    int b = Integer.valueOf(str).intValue()

catch (NumberFormatException e) {

    e.printStackTrace();

}

在转换过程中需要注意,因为字符串中可能会出现非数字的情况,所以在转换的时候需要捕捉处理异常