adding and incrementing data structure elements simultaneously with a faster time possible
<p>I need to add the new element and increment the other objects of an array of objects (elemt) simultaneously with a faster time. </p>

<pre><code>public class elemt {

    public int x;
    public int y;

    public elemt(int a, int b){
        this.x= a;
        this.y= b;
    }


    public void inc(){
     x++;
    }

    int getX(){
        return x;
    }

    int getY(){
        return y;
    }


}

//----------------


public class TAD {

   public static ArrayList &lt; elemt &gt;  A1 = new ArrayList &lt; elemt &gt; ( ); // first array

   public static ArrayList &lt; elemt &gt; A2 = new ArrayList &lt; elemt &gt; ( ); // second array

     public static void main(String[] args){

   //------- first test -------------- 

        for(int i=0; i&lt;10000000; i++){
           A1.add(new elemt(i, i));    // fill array A1 
          }


         long t0 = System.currentTimeMillis();

          T1.add(0, new elemt(1, 1));  // calculate te time of adding one element in filled array A1

         long t1= System.currentTimeMillis()- t0;

         System.out.println("Time first test : "+t1);




   //----------- Second Test ------------

         for(int i=0; i&lt;10000000; i++){
           A2.add(new elemt(i, i));     // fill array A2
          }


        long t2 = System.currentTimeMillis();

           A2.add(0, new elemt(1, 1)); // adding one element in filled array A2

            for(int i=1; i&lt;T.size(); i++){
              A2.get(i).inc();     // Increment all element of A2 from position 1.
            }

        long t3= System.currentTimeMillis()- t2;

      System.out.println("Time second test: "+t3);



     }
</code></pre>

<p>//------- The results:</p>

<p>Time without Incrementation : 15 ms</p>

<p>Time with Incrementation: 156 ms</p>

<p>My objective is to minimize as possible the time of incrementation process </p>

<p>(Time second test &lt; Time first test * 2 )</p>

<p>because actually</p>

<p>Time second test (156 ms) =  Time first test (15 ms )* 10  </p>

<p>I notes that i can added a new element in any position, but i chose the worst case (adding an element in the first position that requires the incrementation of all <strong>x</strong> element of the arraylist) </p>

<p>I tried many data structure as vector, hashmap ,... but I could not minimize the time of incrementation</p>
