温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Java面向对象中基本数据、包装类怎么用

发布时间:2021-12-30 15:14:29 来源:亿速云 阅读:110 作者:小新 栏目:编程语言

这篇文章主要为大家展示了“Java面向对象中基本数据、包装类怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Java面向对象中基本数据、包装类怎么用”这篇文章吧。

/**
	知识点: 基本数据类型 对应的 包装类
		1. 基本数据类型包括:
			1. 数值类型
				1.1 byte    ->   Byte
				1.2 short   ->   Short
				1.3 int     ->   Integer
				1.4 long    ->   Long
				1.5 float   ->   Float
				1.6 double  ->   Double
			2. 字符型
				2.1 char    ->   Character
			3. 布尔型
				3.1 boolean ->   Boolean
		2. 包装类的应用
			2.1 使基本数据类型也可以有引用类型
			2.2 实现数据类型的转换功能
	注意:
		1. 在jdk 1.5 之后 基本数据类型和包装类型是可以相互赋值
*/public class WrapClass {	
	public static void main(String[] args)
	{
		Byte a=1;		byte b=10;
		a=b;
		System.out.println(a.byteValue());
		System.out.println(Integer.valueOf(b));		//包装类的应用 主要是  数据类型的转换
		//整型转  double 型
		int c=100;
		Integer d=new Integer(c);
		System.out.println(d.doubleValue());		//整型转 long 型
		System.out.println(d.longValue());		//整型转 字符串
		String str=Integer.toString(d);
		System.out.println(str);		//字符串转 整型
		int e=Integer.parseInt(str);
		System.out.println(e);
		System.out.println(Integer.toBinaryString(e));
		System.out.println(Integer.signum(e));
		System.out.println(Integer.bitCount(e));
		System.out.println(Integer.highestOneBit(e));
		System.out.println(Integer.numberOfLeadingZeros(e));
	}
}

以上是“Java面向对象中基本数据、包装类怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI