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

CodePudding user response:

reference 1st floor fai_jai response:
index can be used to delete to delete the specified location element, directly in the table below left null
your approach can, but I don't understand why, after the array arr to arr2 changes after arr arr2 changes

CodePudding user response:

reference luyaocode reply: 3/f
Quote: refer to 1st floor fai_jai response:
index can be used to delete to delete the specified location element, directly in the table below left null
your approach can, but I don't understand why, after the array arr to arr2 changes after arr arr2 changes

What have you been arr2=arr; the

CodePudding user response:

I see,=is the address

CodePudding user response:

reference 4 floor stand green _ response:
Quote: refer to the third floor luyaocode response:
Quote: refer to 1st floor fai_jai response:
index can be used to delete to delete the specified location element, directly in the table below left null
your approach can, but I don't understand why, after the array arr to arr2 changes after arr arr2 changes

What have you been arr2=arr; The

Understand, is the address

CodePudding user response:

Pointed to the arrr arr2, arr2 and arr is the same thing. So see is change together
  • Related