How do I remove objects from an array in Java?

前端 未结 20 1371
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 02:01

    Something about the make a list of it then remove then back to an array strikes me as wrong. Haven't tested, but I think the following will perform better. Yes I'm probably unduly pre-optimizing.

    boolean [] deleteItem = new boolean[arr.length];
    int size=0;
    for(int i=0;i

提交回复
热议问题