title: Convert textbox input to integer Java
body: <p>I made 8 text box fields that I'm getting input from. If there is no input the value needs to be zero. input1/2/3 etc are integers. These text fields are made using SWT.</p>
  
  <p>So far I've come up with this:</p>
  
  <pre><code>if (text_1.getText().trim().equals("")) {
      input1 = 0;
  } else {
      input1 = Integer.parseInt(text_1.getText());
  }
  
  if (text_2.getText().trim().equals("")) {
      input2 = 0;
  } else {
      input2 = Integer.parseInt(text_2.getText());
  }
  </code></pre>
  
  <p>I don't want to copy/paste this eight different times, does anyone have any ideas? </p>
  
  <p>Edit: I just saw something like this after posting in the suggested field, but I'm having a hard time implementing it. <a href="https://stackoverflow.com/questions/24501280/parse-several-textboxes-java?rq=1">Parse several textboxes (Java)</a></p>
  
  <p>Thanks</p>