title: How to shift array list elements to the right with some index at fixed position in java
body: <p>I have an array list with a size of 10 elements. What I am trying to achieve here is that when I add an element at any index, the element which is next to it should get shifted except at some fixed indexes.</p>
  
  <p>For example, Let's say my array list is as follows</p>
  
  <p><strong>[10, 20, 30, 40, 50,60,70,80,90,100]</strong></p>
  
  <p><strong>indexes are {0,1,2,3,4,5,6,7,8,9}</strong></p>
  
  <p><strong>fixed indexes{4,6}</strong></p>
  
  <p>when I remove an element from index  <strong>10</strong> and add an index <strong>3</strong> the output should be as follows</p>
  
  <p><strong>[10, 20, 30, 100, 50, 40,70,60,80,90,]</strong></p>
  
  <p>if you notice the values at indexes <strong>{4,6}</strong> did not change after adding <strong>10 th</strong> element at index <strong>3</strong>.</p>
  
  <pre><code>    List&lt;Integer&gt; values = new ArrayList&lt;&gt;();
      values.add(10);
      values.add(20);
      values.add(30);
      values.add(40);
      values.add(50);
      values.add(60);
      values.add(70);
      values.add(80);
      values.add(90);
      values.add(100);
      System.out.println(values);
  
      values.removeAt(9)
      values.add(3,100);
      System.out.println(values);
  
      # Output
      [10, 20, 30, 40, 50,60,70,80,90,100]
      [10, 20, 30, 100, 40,50,60,70,80,90]
  </code></pre>
  
  <p>If anyone can Suggest any sorting method or collections to achieve this it will be really helpful.</p>
  
  <p>Sample input and outputs:</p>
  
  <p>int[] a= [7, 4, 3, 2, 1, 5, 6, 4, 8, 9] and fixed indexes are {1,2}</p>
  
  <p>Remove 6th index element (6) and add at index 0
  The output should be as follows:</p>
  
  <p>[6, 4, 3, 7, 2, 1, 5, 4, 8, 9]</p>