How can ArrayList.remove () remove a specific number in an Integer array?

If you pass a number without quotes in the parameters of the method, it means an index, in quotes it does not work ...

import java.util.ArrayList; public class Circle { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(2); list.add(1); list.add(3); list.remove("2"); //что писать в скобках? System.out.println(list); } } 
  • 2
    new Integer (2). If you pass int, then deletes by index. If the object, then the object equals. - aleshka-batman

1 answer 1

ArrayList provides two overloaded remove () methods.

but. remove (int index): Accept the index of the object to be deleted.

b. remove (objct obj): accept an object to be deleted.

That is, to delete a specific value, you need to enter this: list.remove (new TypeArrayList (yourValue)), where TypeArrayList is Integer in your case, and yourValue is your particular number