当前位置: 首页 > news >正文

做网站模板哪里买百度企业网盘

做网站模板哪里买,百度企业网盘,卖域名出去客户犯法怎么办,阿里网站域名指向怎么做在本教程中,我们将看到将Java中的String转换为int(或Integer)的各种方法。 您可以使用以下任何一种方式: –使用Integer.parseInt(string) –使用Integer.valueof(string) –使用…

在本教程中,我们将看到将Java中的String转换为int(或Integer)的各种方法。

您可以使用以下任何一种方式:

–使用Integer.parseInt(string)

–使用Integer.valueof(string)

–使用Apache Commons NumberUtils.toInt(string)

–使用Apache Commons NumberUtils.createInteger(string)

–使用Guava库的Ints.tryParse(string)方法

–使用Integer.decode(string)

–使用新的整数(字符串)

使用Integer.parseInt(string)

String empId1 = "1001";
int intEmpId1 = Integer.parseInt(empId1);
System.out.println(intEmpId1);Output :
1001

在以下情况下,Integer.parseInt()将引发NumberFormatException:

/ Alphabets in the input.Integer.parseInt("100AB");//Input number is greater than the Integer range.Integer.parseInt("2147483648");//Number with decimalInteger.parseInt("1.1"); //empty StringInteger.parseInt(""); //Blank spaceInteger.parseInt(" ");

使用Integer.valueof(string)

String empId2 = "2001";Integer integerEmpId2 = Integer.valueOf(empId2);
System.out.println(integerEmpId2);Output :
2001

使用Apache Commons NumberUtils.toInt(string)

String empId3 = "3001";
int intEmpId3 = NumberUtils.toInt(empId3);
System.out.println(intEmpId3);Output :
3001int intEmpId4 = NumberUtils.toInt(null);
System.out.println(intEmpId4);Output :
0int intEmpId5 = NumberUtils.toInt("1001ABC");
System.out.println(intEmpId5);Output :
0int intEmpId6 = NumberUtils.toInt("1001ABC", 10);
System.out.println(intEmpId6);Output :
10

使用Apache Commons NumberUtils.createInteger(string)

String empId4 = "4001";
Integer integerEmpId7 = NumberUtils.createInteger(empId4);
System.out.println(integerEmpId7);Output :
4001

使用Guava库的Ints.tryParse(string)方法

String empId5 = "5001";
Integer integerEmpId8 = Ints.tryParse(empId5);System.out.println(integerEmpId8);Output :
5001

使用Integer.decode(string)

String empId6 = "6001";
Integer integerEmpId9 = Integer.decode(empId6);
System.out.println(integerEmpId9);Output :
6001

使用新的整数(字符串)

String empId7 = "7001";
Integer integerEmpId10 = new Integer(empId7);
System.out.println(integerEmpId10);Output :
7001

但是,请记住,从Java9开始不推荐使用此Integer构造函数。

完成程序

package com.blogspot.javasolutionsguide.stringtointexample;import org.apache.commons.lang3.math.NumberUtils;
import com.google.common.primitives.Ints;public class StringToInt {public static void main(String[] args) {String empId1 = "1001";int intEmpId1 = Integer.parseInt(empId1);System.out.println(intEmpId1);String empId2 = "2001";Integer integerEmpId2 = Integer.valueOf(empId2);System.out.println(integerEmpId2);String empId3 = "3001";int intEmpId3 = NumberUtils.toInt(empId3);System.out.println(intEmpId3);int intEmpId4 = NumberUtils.toInt(null);System.out.println(intEmpId4);  int intEmpId5 = NumberUtils.toInt("1001ABC");System.out.println(intEmpId5);int intEmpId6 = NumberUtils.toInt("1001ABC", 10);System.out.println(intEmpId6);String empId4 = "4001";Integer integerEmpId7 = NumberUtils.createInteger(empId4);System.out.println(integerEmpId7);String empId5 = "5001";Integer integerEmpId8 = Ints.tryParse(empId5);System.out.println(integerEmpId8);String empId6 = "6001";Integer integerEmpId9 = Integer.decode(empId6);System.out.println(integerEmpId9);String empId7 = "7001";Integer integerEmpId10 = new Integer(empId7);System.out.println(integerEmpId10);// Alphabets in the input.Integer.parseInt("100AB");//Input number is greater than the Integer range.Integer.parseInt("2147483648");//Number with decimalInteger.parseInt("1.1"); //empty StringInteger.parseInt(""); //Blank spaceInteger.parseInt(" "); }
}

使用的依赖项:

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.9</version>
</dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>16.0.1</version></dependency>

摘要

因此,在本教程中,我们看到了
–如何在Java中将String转换为int(或Integer)。 –在大多数情况下,如果需要int或Integer,则可以使用Integer.parseInt()和Integer.valueOf() 分别来自String并希望避免依赖第三方库。 – NumberUtils。 toInt ()可用于不希望我们的程序由于NumberFormatException而失败的情况。

翻译自: https://www.javacodegeeks.com/2020/03/how-to-convert-string-to-int-in-java.html

http://www.hkea.cn/news/106297/

相关文章:

  • 网站表单及商品列表详情模板如何搭建自己的网站
  • 网站域名登记证明百度高级搜索怎么用
  • 国外网站在国内做镜像站点网站搭建费用
  • 网站后台如何添加关键词软件开发公司
  • 手机做网站的网站windows优化大师卸载不了
  • 万网速成网站有哪些 功能自己的网站怎么推广
  • 邯郸哪有做网站的河南百度推广公司
  • 我是做环保类产品注册哪些浏览量大的网站推销自己的产品比较好呢西安网站seo优化公司
  • 网页传奇游戏排行昆明网络推广优化
  • 商城模板网站模板网站软文是什么
  • 校园网站推广方案怎么做网站排名推广工具
  • 深圳罗湖企业网站建设报价网络媒体发稿平台
  • 用别人公司域名做网站线下推广的渠道和方法
  • php mysql的网站开发外贸推广平台
  • 济南网站建设认可搜点网络能百度指数有三个功能模块
  • 网上商城网站建设意义在线代理浏览网页
  • 网站图片切换代码百度下载并安装最新版
  • 微信公众平台号申请注册入口杭州seo公司
  • 本周实时热点新闻事件seo文章代写一篇多少钱
  • 旺店通app手机企业版下载网站seo如何优化
  • 宝山区建设用地事务所网站网络公司有哪些
  • 用sql做简单的博客网站大连谷歌seo
  • 新手怎么学做网站就业培训机构有哪些
  • magento网站建设搭建网站步骤
  • 营销网站如何实现差异化南京seo公司
  • 服务器托管是啥搜索引擎优化排名培训
  • 山西手机网站建设网址大全123
  • b2c平台有哪些平台网址新区seo整站优化公司
  • WordPress突然全站404网站如何添加友情链接
  • 复制别人网站做第一站seo短视频网页入口引流下载