谢谢,我知道了,今天写了一遍
[Java] 纯文本查看 复制代码 package array_练习;
public class Array_Conversion {
public static void main(String[] args) {
}
//1.字符串转化为: 字符数组
public char [] stringToCharArray (String string) {
char[] arr = string.toCharArray();
return arr;
}
//2.字符串转化为:整数数组
public int[] stringToIntArray (String string) {
int [] arr = new int [string.length()] ;
char [] c = string.toCharArray() ;
for (int i = 0; i < string.length(); i++) {
arr[i] = c[i];
}
return arr;
}
//3.字符数组转化为:字符串
public String charArrayToString (char [] arr) {
String string = "";
for (char c : arr) {
string += c ;
}
return string;
}
//4.字符数组转化为:整数数组
public int [] charToIntArray (char [] arr) {
int [] arr2 = new int [arr.length];
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
}
//5.整数数组转化为:字符数组
public char [] intArrayToCharArray (int [] arr) {
char [] arr2 = new char [arr.length];
String string = "";
for (int c : arr) {
string += c;
}
arr2 = string.toCharArray();
return arr2;
}
//6.整数数组转化为:字符串
public String intArrayToString (int [] arr) {
String string = "";
for (int i : arr) {
string += i;
}
return string;
}
//
} |