replaceAll不替换子串

Wil*_*son 1 java string replace

我在输入后运行代码

1 qwertyuiopasdfghjklzxcvbnm

它仍然打印出意志而不是替换像它应该的人物,这是为什么?

public static void main(String[] args) 
{

    String input="";
    int cases= sc.nextInt();
    String al= sc.next();
    String upAl= al.toUpperCase();
    char [] upAlph = upAl.toCharArray();


    char[] alph = al.toCharArray();
    for(int i=0; i<cases; i++)
    {
        input=sc.next();

        input.replaceAll("a", ""+ alph[0]);
        input.replaceAll("b", ""+ alph[1]);
        input.replaceAll("c", ""+ alph[2]);
        input.replaceAll("d", ""+ alph[3]);
        input.replaceAll("e", ""+ alph[4]);
        input.replaceAll("f", ""+ alph[5]);
        input.replaceAll("g", ""+ alph[6]);
        input.replaceAll("h", ""+ alph[7]);
        input.replaceAll("i", ""+ alph[8]);
        input.replaceAll("j", ""+ alph[9]);
        input.replaceAll("k", ""+ alph[10]);
        input.replaceAll("l", ""+ alph[11]);
        input.replaceAll("m", ""+ alph[12]);
        input.replaceAll("n", ""+ alph[13]);
        input.replaceAll("o", ""+ alph[14]);
        input.replaceAll("p", ""+ alph[15]);
        input.replaceAll("q", ""+ alph[16]);
        input.replaceAll("r", ""+ alph[17]);
        input.replaceAll("s", ""+ alph[18]);
        input.replaceAll("t", ""+ alph[19]);
        input.replaceAll("u", ""+ alph[20]);
        input.replaceAll("v", ""+ alph[21]);
        input.replaceAll("w", ""+ alph[22]);
        input.replaceAll("x", ""+ alph[23]);
        input.replaceAll("y", ""+ alph[24]);
        input.replaceAll("z", ""+ alph[25]);
        input.replaceAll("A", upAlph[0]+"");
        input.replaceAll("B", upAlph[1]+"");
        input.replaceAll("C", upAlph[2]+"");
        input.replaceAll("D", upAlph[3]+"");
        input.replaceAll("E", upAlph[4]+"");
        input.replaceAll("F", upAlph[5]+"");
        input.replaceAll("G", upAlph[6]+"");
        input.replaceAll("H", upAlph[7]+"");
        input.replaceAll("I", upAlph[8]+"");
        input.replaceAll("J", upAlph[9]+"");
        input.replaceAll("K", upAlph[10]+"");
        input.replaceAll("L", upAlph[11]+"");
        input.replaceAll("M", upAlph[12]+"");
        input.replaceAll("N", upAlph[13]+"");
        input.replaceAll("O", upAlph[14]+"");
        input.replaceAll("P", upAlph[15]+"");
        input.replaceAll("Q", upAlph[16]+"");
        input.replaceAll("R", upAlph[17]+"");
        input.replaceAll("S", upAlph[18]+"");
        input.replaceAll("T", upAlph[19]+"");
        input.replaceAll("U", upAlph[20]+"");
        input.replaceAll("V", upAlph[21]+"");
        input.replaceAll("W", upAlph[22]+"");
        input.replaceAll("X", upAlph[23]+"");
        input.replaceAll("Y", upAlph[24]+"");
        input.replaceAll("Z", upAlph[25]+"");
        input.replaceAll("_", " ");
        pw.println(input);

    }
Run Code Online (Sandbox Code Playgroud)

Rei*_*eus 8

Strings是不可改变的.分配input给结果replaceAll:

input = input.replaceAll("a", ""+ alph[0]);
...
Run Code Online (Sandbox Code Playgroud)

旁白:如果不需要正则表达式,请考虑使用String#replace.