字符串、包装类、原始数据类型间的转换简单示例
  ZklfkKGn8hpZ 2023年11月02日 38 0


在java编程过程中,经常涉及到字符串、包装类、原始数据类型间的转换问题

@Test
	public void demo5()
	{
		String str = "158";
		//----------------------String 转换成Integer类型
		Integer integer =  new Integer(str);        //方式一
		Integer integer1  =  Integer.valueOf(str);  //方式二
		
		//---------------------Integer转换成String
		String str2 = integer.toString();
		
		//---------------------Integer转换成int
		int i =  integer.intValue();
		
		//---------------------int转成Integer
		Integer integer2 = new Integer(i);          //方式一
		Integer integer3 = Integer.valueOf(i);      //方式二
		
		//---------------------String转换成int
		int i2 =  Integer.parseInt(str);
		
		//---------------------int转换成String
		String str4 = String.valueOf(i2);          //方式一
		String str5 = i2+"";	                   //方式二
	}




【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  X5zJxoD00Cah   2023年11月30日   39   0   0 GroupEmail字符串
  gBkHYLY8jvYd   2023年11月19日   26   0   0 输出格式进制字符串
ZklfkKGn8hpZ