How do I remove objects from an array in Java?

前端 未结 20 1376
Happy的楠姐
Happy的楠姐 2020-11-22 01:20

Given an array of n Objects, let\'s say it is an array of strings, and it has the following values:

foo[0] = \"a\";
foo[1]          


        
20条回答
  •  天涯浪人
    2020-11-22 01:42

    Will copy all elements except the one with index i:

    if(i == 0){
                    System.arraycopy(edges, 1, copyEdge, 0, edges.length -1 );
                }else{
                    System.arraycopy(edges, 0, copyEdge, 0, i );
                    System.arraycopy(edges, i+1, copyEdge, i, edges.length - (i+1) );
                }
    

提交回复
热议问题