title: Replace a specific string character index into 0
body: <p>I have built a table chart application. I have a calculate button with an action event. So, first of all, the action event will getText from a textfield button named field. After that it will convert the string into int. But, I want to check one thing before converting the string into int. That is, I would like to check if the string character index [0] is equal to '-', if so then it will be changed to 0. I have tried to put an if condition like</p>
  
  <pre><code>if(text.charAt[0] == "-"){text.setCharAt(0, "0")}
  </code></pre>
  
  <p>but it is saying condition is not comparable from char to string.
  Is there any other way to replace an index character into 0?</p>
  
  <p>Here's the action listener code:</p>
  
  <pre><code>calculate = JButton; result = JTextArea; field = JTextField;
  calculate.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent evt) {
      result.setText(null);
      String text = field.getText();
      Integer i = Integer.valueOf(text);
      for (int j = 1; j &lt;= 10; j++){
      result.append((i + " " + "x" + " " + j + "=" + " " +(i * j)) + "\n");
  }});
  </code></pre>
  
  <p>I have tried the code below but i can't figure out how to assign 'text' to 'str':</p>
  
  <pre><code>    if(text.charAt(0) == '-'){
       StringBuilder str = new StringBuilder(text);
       str.setCharAt(0, '0');
  }        
  </code></pre>
  
  <p>Moreover; when the new string is set to 'str' instead of 'text', I could not assign str as a string, such as <code>StringBuilder str = new StringBuilder(str);</code> Therefore; I am basically stuck in this line.</p>