字符串 ——> 字符数组(char数组)
toCharArray() 方法
String str = "HelloWord";
char[] arr = str.toCharArray();
split("")和split(" ")
String[] arr1 = str.split("");
String[] arr2 = str.split(" ");
字符数组————>字符串
valueof() 方法
String str= String.valueOf(chrCharArray);
StringBuffer ————>String
String str1 = new String(buffer);
String str2 =buffer.toString();
String————>StringBuffer
StringBuffer buffer = new StringBuffer(str);
StringBuffer buffer = new String Buffer();
buffer.append(str);
字符串数组 ——> 字符串
String[] str = {"ab","cd","ef"};
StringBuffer sb = new StringBuffer();
for(int i = 0; i < str.length;i++){
sb.append(str[i]);
}
String s = sb.toString();
System.out.println(s);
基本类型 ————> 字符串
boolean a = true;
char b = 'b';
char[] c = {'a','b','c'};
double d = 100.01;
System.out.println(String.valueOf(a));
int a = 1234;
String str = Integer.toString(a);
字符串 -> 整型
String str = "1234";
int a = Integer.parseInt(str)
int b = Integer.valueOf(str)
|