当前位置:网站首页>如何将数字字符串转换为整数
如何将数字字符串转换为整数
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() {
}
}
边栏推荐
- FL Studio 20 unlimited trial fruit arranger Download
- A simple method of adding dividing lines in recyclerview
- Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
- Programmers' entrepreneurial trap: taking private jobs
- Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
- 历经一个月,终于拿到金蝶Offer!分享一下四面面经+复习资料
- Crawl with requests
- Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)
- Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
- 反正切熵(Arctangent entropy):2022.7月最新SCI论文
猜你喜欢

2022 东北四省赛 VP记录/补题

Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture

AOSP ~ NTP ( 网络时间协议 )

Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable

Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)

EPS电动转向系统分析

进程与线程

机器学习 3.2 决策树模型 学习笔记(待补)

封装一个koa分布式锁中间件来解决幂等或重复请求的问题

MATLAB提取不規則txt文件中的數值數據(簡單且實用)
随机推荐
2. Hal hardware abstraction layer
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
MATLAB提取不规则txt文件中的数值数据(简单且实用)
Using onvif protocol to operate the device
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
After a month, I finally got Kingdee offer! Share tetrahedral Sutra + review materials
如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
FL Studio 20 unlimited trial fruit arranger Download
POI excel 单元格换行
How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
IIS does not take effect after modifying the configuration information
The element form shows the relationship between elementary transformation and elementary matrix
[VTK] vtkPolydataToImageStencil 源码解读
帝国cms 无缩略图 灵动标签(e:loop)判断有无标题图片(titlepic)的两种写法
Bi skills - permission axis
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution