String和八种基本数据类型互相转换

	//String转换为对应的八种基本数据类型
	String str="100";   //Value out of range. Value:"200" Radix:10
	System.out.println("byte:  "+Byte.parseByte(str));
	System.out.println("Short:  "+Short.parseShort(str));
	System.out.println("Integer:  "+Integer.parseInt(str));
	System.out.println("Long:  "+Long.parseLong(str));
	
	char[] arr = "string".toCharArray();
	System.out.println(Arrays.toString(arr)); 
	
	System.out.println("float:  "+Float.parseFloat(str));
	System.out.println("double:  "+Double.parseDouble(str));
	System.out.println("boolean:  "+Boolean.parseBoolean(str));



	//八种基本数据类型转换为String类型
	System.out.println("1toString    "+String.valueOf(43)); //方式一
	
	System.out.println("2toString    "+Integer.toString(43));//方式二
	System.out.println(Character.toString('u2312'));
	System.out.println(Double.toString(12.22));  
	
	System.out.println("3toString    "+43); //方式三

  

原文地址:https://www.cnblogs.com/1020182600HENG/p/6765820.html