How to remove specific object from ArrayList in Java?

前端 未结 13 1659
旧时难觅i
旧时难觅i 2020-12-05 06:54

How can I remove specific object from ArrayList? Suppose I have a class as below:

import java.util.ArrayList;    
public class ArrayTest {
    int i;

    pu         


        
13条回答
  •  孤城傲影
    2020-12-05 08:00

    use this code

    test.remove(test.indexOf(obj));
    
    test is your ArrayList and obj is the Object, first you find the index of obj in ArrayList and then you remove it from the ArrayList.
    

提交回复
热议问题