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.
Method 1:
String test = "ls | grep $name -option";
test = test.replace("$name",textField.getText());
new ProcessBuilder.command(test.split(" "));
Method 2:
String[] test = { "ls", "|", "grep", "$name", "-option" };
String[] newTest = { test[0], test[1], test[2], textField.getText(), test[4] };
new ProcessBuilder.command(newTest);
The second method will be more efficient in overall performance (because of replace
method implementation and split
method call).
But in this case there will be no significant difference in execution time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.