title: Convert Spinner String values "20-34" as integer from 20 to 34 in android
body: <p>How can i convert a Spinner String values such as "20-34",35-44"etc into integer from 20 to 34, integer from 35 to 44 in android.Below is the code for taking integer values from spinner and assigning points in order to a mathematics calculations</p>
  
  <pre><code> public static int age_value(String gender, String ag) {
  
      int b;
      b = Integer.parseInt(ag);
      if (gender.equals("f")) {
          if (20 &lt;= b &amp;&amp; b &lt;= 34) {
              ageValue = -7;
          } else if (35 &lt;= b &amp;&amp; b &lt;= 39) {
              ageValue = -3;
          } else if (40 &lt;= b &amp;&amp; b &lt;= 44)
              ageValue = 0;
          else if (45 &lt;= b &amp;&amp; b &lt;= 49)
              ageValue = 3;
          else if (50 &lt;= b &amp;&amp; b &lt;= 54)
              ageValue = 6;
          else if (55 &lt;= b &amp;&amp; b &lt; 59)
              ageValue = 8;
          else if (60 &lt;= b &amp;&amp; b &lt;= 64)
              ageValue = 10;
          else if (65 &lt;= b &amp;&amp; b &lt;= 69)
              ageValue = 12;
          else if (70 &lt;= b &amp;&amp; b &lt;= 74)
              ageValue = 14;
          else if (75 &lt;= b &amp;&amp; b &lt;= 79)
              ageValue = 16;
  
      } else if (gender.equals("m")) {
          if (20 &lt;= b &amp;&amp; b &lt;= 34) {
              ageValue = -9;
          } else if (35 &lt;= b &amp;&amp; b &lt;= 39) {
              ageValue = -4;
          } else if (40 &lt;= b &amp;&amp; b &lt;= 44)
              ageValue = 0;
          else if (45 &lt;= b &amp;&amp; b &lt;= 49)
              ageValue = 3;
          else if (50 &lt;= b &amp;&amp; b &lt;= 54)
              ageValue = 6;
          else if (55 &lt;= b &amp;&amp; b &lt; 59)
              ageValue = 8;
          else if (60 &lt;= b &amp;&amp; b &lt;= 64)
              ageValue = 10;
          else if (65 &lt;= b &amp;&amp; b &lt;= 69)
              ageValue = 11;
          else if (70 &lt;= b &amp;&amp; b &lt;= 74)
              ageValue = 12;
          else if (75 &lt;= b &amp;&amp; b &lt;= 79)
              ageValue = 13;
  
      }
  
  
      return ageValue;
  
  
  }
  </code></pre>
  
  <p>Below shows the spinner to which the above method is added</p>
  
  <pre><code>  int array1 = R.array.gender;
      // final String[] gender1 = getResources().getStringArray(R.array.gender);
      final ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this.getApplicationContext(), array1, R.layout.simple_spinner_item);
      adapter.setDropDownViewResource(R.layout.spinnerdrop);
      Gender.setAdapter(adapter);
      Gender.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              rowgender = parent.getItemAtPosition(position).toString();
  
  
              if(rowage!=null &amp;&amp; rowgender!=null) {
                  MainActivity.age_value(rowgender, rowage);
              }
  
              Gender.setSelection(position);
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
  
      });
  </code></pre>
  
  <p>but it shows an error </p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: Invalid int: "20–34"</p>
  </blockquote>