拥有一个字符串,替换然后执行拆分或拥有一个字符串数组并创建一个新字符串来更改它,效率更高?

I am undecided what I should do when it comes to prepare the argument for the ProcessBuilder.command method. The method 1 is definitely faster but I am looking for the best efficiency here.

方法1:

String test = "ls | grep $name -option";
test = test.replace("$name",textField.getText());
new ProcessBuilder.command(test.split(""));

方法2:

String[] test = { "ls", "|", "grep", "$name", "-option" };
String[] newTest = { test[0], test[1], test[2], textField.getText(), test[4] };
new ProcessBuilder.command(newTest);