@Test
public void test1(){
List<Param> stringList1 = new LinkedList<Param>(){{
add(new Param(1,"1111"));
add(new Param(2, "2222"));
add(new Param(3, "3333"));
}};
List<Param> stringList2 = new LinkedList<Param>(){{
add(new Param(1,"1111"));
add(new Param(2, "4444"));
add(new Param(3, "5555"));
}};
Map<Integer, String> tmpList2 = stringList2.stream().collect(Collectors.toMap(Param::getId, Param::getName));
var tmplist = stringList1.stream().filter(item -> (tmpList2.get(item.getId()) != null && tmpList2.get(item.getId()).equals(item.getName()))).collect(Collectors.toList());
System.out.println(tmplist);
}
@Setter
@Getter
@ToString
@AllArgsConstructor
public static class Param{
private Integer id;
private String name;
}
@Test
public void test1(){
List<Param> stringList1 = new LinkedList<Param>(){{
add(new Param(1,"1111", "b"));
add(new Param(2, "2222", "c"));
add(new Param(3, "3333", "a"));
}};
List<Param> stringList2 = new LinkedList<Param>(){{
add(new Param(1,"1111", "c"));
add(new Param(2, "4444", "b"));
add(new Param(3, "5555", "a"));
}};
Map<Integer, String> tmpList2 = stringList2.stream().collect(Collectors.toMap(Param::getId, Param::getName));
var tmplist = stringList1.stream().filter(item -> (tmpList2.get(item.getId()) != null && tmpList2.get(item.getId()).equals(item.getName()))).collect(Collectors.toList());
System.out.println(tmplist);
Map<Integer, Param> tmpList3 = stringList2.stream().collect(Collectors.toMap(Param::getId, Function.identity()));
var tmplist2 = stringList1.stream().filter(item -> (tmpList3.get(item.getId()) != null && tmpList3.get(item.getId()).getType().equals(item.getType()))).collect(Collectors.toList());
System.out.println(tmplist2);
}
@Setter
@Getter
@ToString
@AllArgsConstructor
@EqualsAndHashCode
public static class Param{
private Integer id;
private String name;
private String type;
}