title: Solution for very long (if statement)
body: <p>I am new for programming and android development, I'm trying to make an app for length unit conversions. I used two spinner(from unit and to unit), so I need to check what user have selected in the both spinner and then return the value. My problem is I have got very long if statement, so I wonder if there is better solution for this.</p>
  
  <p>Sorry for my poor english, I hope you understand what I mean.</p>
  
  <p>here is the function for length:</p>
  
  <pre><code>public double lengthConversion() {
      double res = 0.0;
  
      num = Double.parseDouble(editTextNum.getText().toString());
  
      // first spinner is mm, second spinner is mm
      if (posFrom == 0 &amp;&amp; posTo == 0) {
          res = num;
      } else if (posFrom == 0 &amp;&amp; posTo == 1) { //second spinner is cm
          res =  num / 10;
      } else if (posFrom == 0 &amp;&amp; posTo == 2) { // dm
          res =  num / 100;
      } else if (posFrom == 0 &amp;&amp; posTo == 3) { // m
          res =  num / 1000;
      } else if (posFrom == 0 &amp;&amp; posTo == 4) { // km
          res =  num / 1000000;
      }
  
      if (posFrom == 1 &amp;&amp; posTo == 0) {
          ....
      } else if (posFrom == 1 &amp;&amp; posTo == 1) {
          ....
      } else if (posFrom == 1 &amp;&amp; posTo == 2) {
          ....
      } else if (posFrom == 1 &amp;&amp; posTo == 3) {
          ....
      } else if (posFrom == 1 &amp;&amp; posTo == 4) {
          ....
      }
  
      .
      .
      .
  
  
      if (posFrom == 4 &amp;&amp; posTo == 0) {
          ...
      } else if (posFrom == 4 &amp;&amp; posTo == 1) {
          ...
      } else if (posFrom == 4 &amp;&amp; posTo == 2) {
          ...
      } else if (posFrom == 4 &amp;&amp; posTo == 3) {
          ...
      } else if (posFrom == 4 &amp;&amp; posTo == 4) {
          ...
      }
  
      return res;
    }
  </code></pre>
  
  <p>and that is the string array I use:</p>
  
  <pre><code>&lt;string-array name="array_length"&gt;
      &lt;item&gt;mm&lt;/item&gt;
      &lt;item&gt;cm&lt;/item&gt;
      &lt;item&gt;dm&lt;/item&gt;
      &lt;item&gt;m&lt;/item&gt;
      &lt;item&gt;km&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>