当前位置:网站首页>如何将数字字符串转换为整数
如何将数字字符串转换为整数
2022-07-03 10:23:00 【zhang__1234】
如"12345",转换为12345这种形式
package com.isea.java;
public class Test {
public static void main(String[] args) {
String str = "1234";
Integer num1 = new Integer(str);
int num2 = Integer.parseInt(str);
Integer num3 = Integer.valueOf(str);
System.out.println(num1 + "\t" + num2 + "\t" + num3);//1234 1234 1234
}
}
以上三种方式均可
关于Integer类应该知道的
Integer a=1;
Integer b=1;
System.out.println(a==b);//true
Integer c=128;
Integer d=128;
System.out.println(c==d);//false
第一个输出true,第二个输出false
因为对于Integer类 当数字处于-128到127之间的时候 是可以直接取出的
以下为源码 涉及到Integer里面的一个缓存
当大于127的时候 就相当于new Integer(x)了 ==比较的为地址 所以第二个为false
private static class IntegerCache {
static final int low = -128;
static final int high;
static final Integer cache[];
static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
}
high = h;
cache = new Integer[(high - low) + 1];
int j = low;
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++);
// range [-128, 127] must be interned (JLS7 5.1.7)
assert IntegerCache.high >= 127;
}
private IntegerCache() {
}
}
边栏推荐
- C language two-dimensional array
- 使用onvif协议操作设备
- Analysis of JMM memory model
- How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression
- MATLAB提取不規則txt文件中的數值數據(簡單且實用)
- 英特尔13代酷睿旗舰曝光,单核5.5GHz
- 线性表的双链表
- How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
- 帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
- Arctangent entropy: the latest SCI paper in July 2022
猜你喜欢
反正切熵(Arctangent entropy):2022.7月最新SCI论文
php服务器 与redis交互大量CLOSE_WAIT分析
MATLAB提取不规则txt文件中的数值数据(简单且实用)
2022 东北四省赛 VP记录/补题
Leetcode 46: full arrangement
英特尔13代酷睿旗舰曝光,单核5.5GHz
[OBS] configFile in ini format of OBS
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
Multi dimensional monitoring: the data base of intelligent monitoring
随机推荐
C语言 AES加解密
VPP三层网络互联配置
帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
One hot code
ASP. Net hotel management system
Program process management tool -go Supervisor
CorelDRAW Graphics Suite 2022新版功能详情介绍
Key switch: press FN when pressing F1-F12
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
Linear table sequence table comprehensive application problem p18
PHP server interacts with redis with a large number of close_ Wait analysis
00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
POI excel 单元格换行
Asyncio warning deprecationwarning: there is no current event loop
phpcms 提示信息页面跳转showmessage
Tencent micro app to get wechat user information
C语言日志库zlog基本使用
程序员的创业陷阱:接私活
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
Application of high-precision indoor positioning technology in safety management of smart factory