Home > Back-end > For array delete operation problem
For array delete operation problem
Time:03-19
//delete specified location elements, and return the original array The class Del2 { The static String [] del2 (String [] arr, int index) {//index starting from 1 String [] arr2=new String (arr. Length), Arr2=arr; System. Arraycopy (arr, index, arr, index 1, arr. Length - index); Arr/arr. Length - 1=null; System. The out. Println (" # # # # # # # # # # # # # "new array). For (String m: arr) { System. The out. Println (m); }
System. The out. Println (" # # # # # # # # # # # # # old array "); For (String m: arr2) { System. The out. Println (m); } Return arr2; }
Why the output of the old and new array is the same? New array # # # # # # # # # # # # # Aa Bb Dd Ee Null # # # # # # # # # # # # # old array Aa Bb Dd Ee Null
CodePudding user response:
The index can be used to delete to delete the specified location element, null directly in the table below