fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception {
  11. int[]my_array ={10,20,30,40,50};
  12.  
  13. System.out.println("Original Array:"+Arrays.toString(my_array));
  14.  
  15. //Remove the second element (index->3,value->40) of the array
  16. int removeIndex =3;
  17.  
  18. for(int i =removeIndex; i<my_array.length-1; i++){
  19. my_array[i] = my_array[i+1];
  20. }
  21. //We cannot alter the size of an array, after the removal, the last element the array will exist twic
  22. System.out.println("After removing the third element:"+Arrays.toString(my_array));
  23. }
  24. }
Success #stdin #stdout 0.13s 54012KB
stdin
Standard input is empty
stdout
Original Array:[10, 20, 30, 40, 50]
After removing the third element:[10, 20, 30, 50, 50]