整理类型转换


字符串和字节数组
String str = "罗长";

byte[] sb = str.getBytes();//字符串转字节数组
byte[] b={(byte)0xB8,(byte)0xDF,(byte)0xCB,(byte)0xD9};

String str= new String (b);//字节数组转字符串

字符串和字符数组
string str = "mytest";  
 char[] chars = str.ToCharArray(); //字符串转字符数组

char[] chs = new char[]{’a’,’b’,’c’,’d’,’e’};

 String s4 = new String(chs); //字符数组转字符串

字符串和基本数据类型
int i=Integer.parseInt("123");//字符串转基本数据类型

//基本数据类型转字符串的三种方法

“sum”=1+1;//1.双引号:“”+基本数据类型

String i=String.valueOf(122);//2.调用String类中的valueof方法

String i=Double.toString(12.1);//3.调用包装类中独有的tostring方法



基本数据类型和包装对象
Integer i=new Integer(111);//基本数据类型转包装类型对象

Integer i=Integer.valueOf(111);//封装成包装类型

int num=i.intValue();//包装类转基本数据类型

原文地址:https://www.cnblogs.com/111wdh/p/13292407.html