Removing an element from a List not working as expected

前端 未结 3 1246
我寻月下人不归
我寻月下人不归 2021-01-24 21:54

I have an ArrayList of String arrays which is added to like so:

List data = new ArrayList<>();
data.add(new String[] {var, lex, valor});
         


        
3条回答
  •  不要未来只要你来
    2021-01-24 22:31

    data.remove(new String[]{var, lex, valor});
    

    Will never work because even if the arrays contain the same thing, they are not equal to each other, and the array will not be found in the list.


    public void eliminarPos(String var, String lex, String valor, Integer ii) {
        boolean uno=data.remove(ii);
        System.out.println(uno);
    }
    

    Will not work because you pass it an Integer instead of an int. An Integer is an object, so it is searching the list for that object. Change it to:

    public void eliminarPos(String var, String lex, String valor, int ii) {
        data.remove(ii);
    }
    

提交回复
热议问题