title: How to implement multithreading with a return value?
body: <p>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)</p>
  <p>Here you can see the code for which I want to start a second thread for:</p>
  <pre><code>public String calculate() {
  //The input (StringBuilder) gets converted to an ArrayList
          String[] tmpArray = inputAsText.toString().split(&quot; &quot;);
          inputAsArrayList = new ArrayList(Arrays.asList(tmpArray));
  
  //Other functions are called to perform calculations on
          inputAsArrayList = calculateFor(&quot;x&quot;, &quot;÷&quot;);
          inputAsArrayList = calculateFor(&quot;+&quot;, &quot;-&quot;);
  
  //The answer gets retrieved from the arrarList and returned as a String
          String answer = String.valueOf(inputAsArrayList.get(0));
          clearInput();
          return answer;
      }
  </code></pre>