String–>int
String str="111";
① int a1=Integer.valueOf(str);
② int a2=Integer.parseInt(str);
Int–>String
int i=222;
① String str1=""+i;
② String str2=String.valueOf(int n);
③ String str3=Integer.toString(int i);
Char–>String
① String str=String.valueOf(char ch);
String–>Char
String str="aaaa"
① char ch=str.charAt(0);
Char[]–>String
char ch[]={'a','b','c'};
① String str1=new String(ch);
② String str=String.copyValueOf(ch);
③ StringBuffer sf=new StringBuffer();
for( char c:ch) {
sf.append(c);}
System.out.println(sf.toString());
String–>char[]
String str="abcd";
① char[] ch=new char[str.length()];
for(int i=0;i<str.length();i++) {
ch[i]=str.charAt(i);
}
② ch=str.toCharArray();
Int[]–>String
int [] arr= {1,2,3,4};
① String str=Arrays.toString(arr); //[1, 2, 3, 4]
② StringBuffer sf=new StringBuffer();
for(int a:arr) {
sf.append(a);
}
System.out.println(sf.toString()); //1234
String–>int[]
① int arr[]=new int[str.length()];
String[] str1=str.split("");
for(int i=0;i<str1.length;i++) {
arr[i]=Integer.parseInt(str1[i]);}
Char–>int(数字)
char ch='6';
要先判断是否为数字 :if(characte.isDigit(ch))
String str=String.valueof(ch);
① Integer.valueof(str);
② Integer.paseInt(str);
Char–>int(ascil表)
① int num=ch;
Int–>char
① char ch=(char)num;
Int–>char(数)
① char ch=(char)(num+’0’) //6