title: Conversion of AtomicInteger to int
body: <p>I wrote a thread and for memory synchronization I have to use Atomicinteger. Here is my code:</p>
  
  <pre><code>public class NewClass implements Runnable {
  
  public double rr;
  public double rmse_new;
  public double rmse_newT;
  private int k;
  private int[][] Xdisc;
  
  public NewClass(int Xdisc[][], double[][] pat_cand, int k, double[][] Yresid, double[][] Xresid) {
  
      this.k = k;
      this.Xdisc = Xdisc;
  }
  
  @Override
  public void run() {
      final AtomicInteger q = new AtomicInteger(0);
      q.set(0);
      while (true) {
          if (q.incrementAndGet() &gt;= Xdisc.length) {
              break;
  
              Integer[] temp_X;
              temp_X = new Integer[Xdisc[0].length];
              for (int s = 0; s &lt; Xdisc[0].length; s++) {
                  temp_X[s] = Xdisc[q][s];
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>the problem is that q is the row index of a 2D array Xdisc (in main class) and apparently should be integer but in NewClass, q is AtomicInteger. Therefore I got this error:</p>
  
  <pre><code>incompatible types
  required: int
  found: AtomicInteger
  </code></pre>
  
  <p>in this line </p>
  
  <pre><code>temp_X[s] = Xdisc[q][s];
  </code></pre>
  
  <p>and I even tried </p>
  
  <pre><code>temp_X[s] = Xdisc[(int)q][s];
  </code></pre>
  
  <p>and got this error:</p>
  
  <pre><code>inconvertible types
  </code></pre>
  
  <p>Is there anyway to convert AtomicInteger to int?</p>