Is there a loop in java that executes multiple methods (or multiple actions) at the same time?
Example:
replace(line1, line2);
replace(line3, line4);
replace(line5, line6);
replace(line7, line8);
replace(line9, line10);
Loop through a file and replace the strings - they aren't in o开发者_运维知识库rder.
Regarding this code in your question's edit:
replace(line1, line2);
replace(line3, line4);
replace(line5, line6);
replace(line7, line8);
replace(line9, line10);
You simply need one method, replace, called by a for or while loop (depending if you know in advance how many times you'll loop). If this doesn't solve your problem, then (again), please ask a better and clearer question.
There's no need to use threads to do these all at the same time. You state that "I only need to do this once", perhaps, but you need to call replace at least 5 times in this example, so actually a loop that calls replace 5 times passing in different parameters would work nicely. If you had an array of pairs of lines, you could loop through the array with a for loop calling replace as you loop. Again there's no need for a "do together" here but rather a "do in order".
But again you seem to be withholding critical information for unknown reasons. Again, I urge you to study this link: How To Ask Questions The Smart Way
精彩评论