The intersection of two list judgments is based on a certain field.

both list store user objects, including id and name, how to filter the intersection based on the same id of the current object without rewriting hashcode and equals?

Mar.14,2021

consider writing an auxiliary function

int find(int id, List<User> list){
    int res = -1;
    for(int i = 0; i < list.size(); i PP){
        if (list.get(i).id == id){
        res = i;
        break;
        }
    }
    return res;
}

then use stream to simplify operations

List<User> list = list2.stream()
    .filter(user -> find(user.id, list1) > -1)
    .collect(Collectors.toList());
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31e7e-2bdca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31e7e-2bdca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?