如:我已有一个字符串数组X(a1 b2 c3 d4)
我想先按(a→1,b→2,c→3,d→4)这样的规律把X变为(11 22 33 44)
再让一个Int 数组Y=(11 22 33 44)
public class a
{
public static void main(String[] args){
//有一个字符串数组X(a1 b2 c3 d4)
String[] x={"a1","b2","c3","d4"};
//按(a→1,b→2,c→3,d→4)这样的规律把X变为(11 22 33 44)
x[0]=x[0].replace("a","1");
x[1]=x[1].replace("b","2");
x[2]=x[2].replace("c","3");
x[3]=x[3].replace("d","4");
//再让一个Int 数组Y=(11 22 33 44)
int[] y=new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i]=Integer.parseInt(x[i]);
}
//结果输出
for (int i = 0; i < y.length; i++) {
System.out.println("Int数组y的第"+i+"个元素是"+y[i]);
}
}
}
你好,你想了解的是这个意思吗,如果有偏差,可以说明一下是哪里理解错误了
代码如下,望采纳
@Test
public void testArray1(){
String[] X = new String[]{"a1","b2","c3","d4"};
String[] Y = new String[X.length];
for (int i = 0; i < X.length; i++) {
String s = X[i].charAt(1) + "";
Y[i] = s+s;
}
List<String> resultStr = Arrays.asList(Y);
System.out.println(resultStr);
}