当前位置:网站首页>如何将数字字符串转换为整数
如何将数字字符串转换为整数
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() {
}
}
边栏推荐
- 使用onvif协议操作设备
- 触摸与屏幕自动旋转调试
- 项目管理精华读书笔记(七)
- MATLAB提取不规则txt文件中的数值数据(简单且实用)
- How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
- FL Studio 20 unlimited trial fruit arranger Download
- Numpy np.max和np.maximum实现relu函数
- AMS Series 1 - AMS startup process
- 2. Hal hardware abstraction layer
- Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
猜你喜欢
Stack, monotone stack, queue, monotone queue
软考中级软件设计师该怎么备考
AMS Series 1 - AMS startup process
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
Intel 13th generation core flagship exposure, single core 5.5ghz
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution
How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
用了这么久线程池,你真的知道如何合理配置线程数吗?
Numpy np.max和np.maximum实现relu函数
DS90UB949
随机推荐
One hot code
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
2022 东北四省赛 VP记录/补题
Multi dimensional monitoring: the data base of intelligent monitoring
如何成为一名高级数字 IC 设计工程师(1-4)Verilog 编码语法篇:表达式
Encapsulation attempt of network request framework of retro + kotlin + MVVM
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
Touch and screen automatic rotation debugging
(二)进制
搭建ADG后,实例2无法启动 ORA-29760: instance_number parameter not specified
如何:配置 ClickOnce 信任提示行为
AOSP ~ NTP ( 网络时间协议 )
EPS电动转向系统分析
(2) Base
VPP三层网络互联配置
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
【obs】obs的ini格式的ConfigFile
1. Hal driven development
C语言 AES加解密