-4

I created an arraylist for Integer values.

 List<Integer> xpos = new ArrayList<Integer>();

adding the integers to the arraylist as follows

 int bt_x=10; 
 xpos.add(bt_x);

Now how to remove single value ie. how to remove an integer from the arraylist. We can remove string arraylist with arraylist.get(i).remove. but how to remove the integer arraylist.

braX
  • 11,506
  • 5
  • 20
  • 33
Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • It's in the documentation. http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html#remove%28java.lang.Object%29 It would be nice of you to check *anything* before asking a question. Regards – Eel Lee Oct 10 '13 at 10:02

2 Answers2

5

Use ArrayList.remove(java.lang.Object) method. like

xpos.remove(Integer.valueOf( premitive int value ));

if you want to remove bt_x then use

xpos.remove(Integer.valueOf(bt_x));

Do not forget to cast int to Integer. If you do not do, it will remove the element at given value.


And yes, Properly removing an Integer from a List<Integer> should be read.

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
2

Use remove() method of arraylist to remove the object from arraylist.. It takes two types of arguments one is object type another is integer type..

remove(Object o)

xpos.remove(10);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59