I have been working on a calculator app in Java and I want to implement multithreading for this. I want to start a second thread, to calculate the answer for the given input. The only problem is, the calculation has to return a value and that value need to get displayed, but I don't know how to handle that. (I know its kind of useless to implement multithreading because the calculation doesn't even take a second, but I want to do it as practice and see if its possible)
Here you can see the code for which I want to start a second thread for:
public String calculate() {
//The input (StringBuilder) gets converted to an ArrayList
String[] tmpArray = inputAsText.toString().split(" ");
inputAsArrayList = new ArrayList(Arrays.asList(tmpArray));
//Other functions are called to perform calculations on
inputAsArrayList = calculateFor("x", "÷");
inputAsArrayList = calculateFor("+", "-");
//The answer gets retrieved from the arrarList and returned as a String
String answer = String.valueOf(inputAsArrayList.get(0));
clearInput();
return answer;
}