国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

網(wǎng)站制作的困難和解決方案成都推廣系統(tǒng)

網(wǎng)站制作的困難和解決方案,成都推廣系統(tǒng),能看wap軟件,長沙做網(wǎng)站找哪家好在本教程中,我們將看到將Java中的String轉(zhuǎn)換為int(或Integer)的各種方法。 您可以使用以下任何一種方式: –使用Integer.parseInt(string) –使用Integer.valueof(string) –使用…

在本教程中,我們將看到將Java中的String轉(zhuǎn)換為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)

–使用新的整數(shù)(字符串)

使用Integer.parseInt(string)

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

在以下情況下,Integer.parseInt()將引發(fā)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

使用新的整數(shù)(字符串)

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

但是,請記住,從Java9開始不推薦使用此Integer構造函數(shù)。

完成程序

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轉(zhuǎn)換為int(或Integer)。 –在大多數(shù)情況下,如果需要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://m.aloenet.com.cn/news/37806.html

相關文章:

  • 蘇州驚天網(wǎng)站制作網(wǎng)想要推廣網(wǎng)頁正式版
  • 山東威海網(wǎng)站開發(fā)關鍵詞推廣排名
  • 做網(wǎng)站被捉域名注冊優(yōu)惠
  • 大型門戶網(wǎng)站有哪些石家莊網(wǎng)絡推廣優(yōu)化
  • 賺錢軟件真實可靠揭陽市seo上詞外包
  • 時光軸 網(wǎng)站sem是什么電鏡
  • 免費淘寶客網(wǎng)站模板seo優(yōu)化需要做什么
  • 嘉祥網(wǎng)站建設中國數(shù)據(jù)網(wǎng)
  • 網(wǎng)站都有什么類型清遠頭條新聞
  • 微信團購網(wǎng)站怎么做seo資源
  • 網(wǎng)站輪播廣告動畫怎么做南京最大網(wǎng)站建設公司
  • 更新網(wǎng)站要怎么做呢鏈接交換
  • 米課做網(wǎng)站軟文素材庫
  • 怎樣免費做網(wǎng)站視頻講解網(wǎng)絡服務電話
  • 已有網(wǎng)站做app需要多少錢寧波谷歌seo推廣
  • 北京網(wǎng)站設計制作教程滄浪seo網(wǎng)站優(yōu)化軟件
  • 哪里有網(wǎng)站建設加盟合作今日新聞最新頭條
  • wordpress所有文章網(wǎng)站排名優(yōu)化推廣
  • 上海整站優(yōu)化公司網(wǎng)絡營銷理論
  • 網(wǎng)站建設與文字的工作成都百度推廣代理公司
  • 傳奇三端互通新開服網(wǎng)站上海推廣服務
  • 西安網(wǎng)站seo優(yōu)化網(wǎng)站運營指標
  • wordpress添加文章分類二級小紅書搜索優(yōu)化
  • 直播網(wǎng)站模板網(wǎng)站優(yōu)化推廣外包
  • 金品誠企網(wǎng)站建設b站2023年免費入口
  • 樂清網(wǎng)站關鍵詞下載
  • 不用ftp做網(wǎng)站seo工作室
  • 建網(wǎng)站的公司不肯簽合同福州seo推廣優(yōu)化
  • 微網(wǎng)站制作軟件線上線下整合營銷方案
  • 推廣業(yè)務網(wǎng)站建設網(wǎng)站服務器速度對seo有什么影響