Skip to content
Advertisement

The property of the object calls removeAll(), why did it delete itself

public static void main(String[] args) {

    Dto dto = new Dto();

    List<Long> aList = new ArrayList<>();
    aList.add(1L);
    aList.add(2L);
    aList.add(3L);
    dto.setIdList(aList);

    List<Long> bList = new ArrayList<>();
    bList.add(1L);
    bList.add(2L);

    List<Long> tempList = dto.getIdList();
    tempList.removeAll(bList);

    System.out.println(dto.getIdList());

}

@Data
public static class Dto{
    public List<Long> idList;
}

This code is a test method I wrote,the code in System.out.println(dto.getIdList());,the dto.getIdList() size is 1,and why not 3?why did it delete itself?

Advertisement

Answer

enter image description here

this is way to solve the problom

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement