Java 常用类库 之 基本类型的包装类
http://www.verejava.com/?id=17159727064934
public class Test {
public static void main(String[] args) {
// 8 种基本数据类型对应的包装类
// byte Byte
// short Short
// int Integer
// long Long
// float Float
// double Double
// char Character
// boolean Boolean
//
// 装箱和拆箱
// 装箱: 将一个基本数据类型转换成包装类 new Integer(int i)
// 拆箱: 将一个包装类转换成基本数据类型 int Integer.intValue();
int i = 100;
Integer integer = new Integer(i);//装箱
System.out.println(i);
System.out.println(integer);
int i2 = integer.intValue();//拆箱
System.out.println(i2);
// int Integer.parseInt(String s)
String str = "200";
int i3 = Integer.parseInt(str);
System.out.println(i3);
// String Integer.toString(int i)
int i4 = 300;
String str2 = Integer.toString(i4);
System.out.println(str2);
// 3. Integer Integer.valueOf(String s)
String str3 = "400";
Integer integer2 = Integer.valueOf(str3);
System.out.println(integer2);
}
}
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Java 常用类库 之 大精度数值
http://www.verejava.com/?id=17159675312132 import java.math.BigDecimal; import java.math.BigInteger; public class Test { public static void main(String[] args) { // 计算 1 到 30 的相乘的结果 BigInteger sum = new BigInteger("1"); for (int i = 1; i <= 30; i++) { sum = sum.multiply(new BigInteger(String.valueOf(i))); } System.out.println(sum); BigInteger bi1 = new BigInteger("20000000002000000002"); BigInteger bi2 = new BigInteger("40000000004000000004"); System.out.println(bi1.add(bi2)); System.out.prin...
-
下一篇
异步编程之委托
前言: 项目中由于大量的数据读取操作,导致每次加载界面都需要长时间等待,因此决定使用异步来获取数据,实现更好的用户体验。 趁此机会,也好好的补充一下自己在异步编程方面的知识! 先从委托开始说起! 委托的定义: 委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递。 委托的特点: 委托类似于 C++ 函数指针,但它们是类型安全的。委托允许将方法作为参数进行传递。委托可用于定义回调方法。方法不必与委托签名完全匹配。 委托的声明: (1). delegate delegate我们常用到的一种声明 Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型。 例:publicdelegateintMethodtDelegate(intx,inty);表示有两个参数,并返回int型。 (2). Action Action是无返回值的泛型委托。 Action 表示无参,无返回值的委托 Action<int,string> 表示有传入参数int,string无返回值的委托 Action<int,string,bool>...
相关文章
文章评论
共有0条评论来说两句吧...

微信收款码
支付宝收款码