How do I remove objects from an array in Java?

前端 未结 20 1681
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:56

    Initial array

       int[] array = {5,6,51,4,3,2};
    

    if you want remove 51 that is index 2, use following

     for(int i = 2; i < array.length -1; i++){
        array[i] = array[i + 1];
      }
    

提交回复
热议问题