Java - remove last known item from ArrayList

前端 未结 3 749
暖寄归人
暖寄归人 2021-02-11 16:39

OK, so here is my ArrayList:

private List clients = new ArrayList();

and here is what I am

3条回答
  •  借酒劲吻你
    2021-02-11 17:25

    It should be:

    ClientThread hey = clients.get(clients.size() - 1);
    clients.remove(hey);
    

    Or you can do

    clients.remove(clients.size() - 1);
    

    The minus ones are because size() returns the number of elements, but the ArrayList's first element's index is 0 and not 1.

提交回复
热议问题