How do I remove objects from an array in Java?

前端 未结 20 1394
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:53

    Make a List out of the array with Arrays.asList(), and call remove() on all the appropriate elements. Then call toArray() on the 'List' to make back into an array again.

    Not terribly performant, but if you encapsulate it properly, you can always do something quicker later on.

提交回复
热议问题