按Java 8中另一个列表的顺序对对象列表进行排序

我有两个清单,如下所述。一个是来自用户的reqList和来自我执行一些操作后发送给用户的resList。我想根据Java 8中reqList的顺序对resList进行排序。

Request Object:     

public class Request{
private int id;
private String name;
}
Request req1 = new Request(2,"USA");
Request req2 = new Request(8,"UK");
Request req3 = new Request(1,"India");
Request req4 = new Request(7,"Mexico");
reqList.add(req1);reqList.add(req2);reqList.add(req3);reqList.add(req4);

Response object:

    public class Response{
    private int id;
    private String name;
    private String city;
    private String desc;
    }
    Response res1 = new Response(1,"India","Delhi", "city found");
    Response res2 = new Response(7,"Mexico","New Mexico", "city Not found");
    Response res3 = new Response(2,"USA","New York", "city found");
    Response res4 = new Response(8,"UK","London", "city found");

    resList.add(res1);resList.add(res2);resList.add(res3);resList.add(res4);```



评论