More efficient way to remove elements from an array list

前端 未结 3 417
说谎
说谎 2021-01-25 12:45

I have developed a array list something like this

ArrayList list = new ArrayList();
list.add(\"1\");
list.add(\"8\");
list.add(\"8\"         


        
3条回答
  •  不思量自难忘°
    2021-01-25 13:23

    Performance wise they should be similar. Have you tested? If you want to use the built in methods, you can do this with a similar performance.(to be confirmed by testing):

    list.removeAll(Arrays.asList("8"));
    

    Finally if you want a list without duplicates, use a Set as others have mentioned.

提交回复
热议问题