I have input of Ids
List<Integer> idList = List.of(100, 101, 102, 103, 104);
from DB i got list of Objects
@Getter
@Builder
public class CustomObject {
private int id;
}
List<CustomObject> fromDB = List.of(
CustomObject.builder().id(102).build(),
CustomObject.builder().id(104).build()
);
I want to see difference between input IDs with response from DB CustomObject list
If response from DB does not contains id from input i want to see this difference
List<Integer> listOfID = fromDB.stream().map(CustomObject::getId).toList();
String list = idList.stream().filter(element -> !listOfID.contains(element)).map(String::valueOf).collect(Collectors.joining(", "));
System.out.println("RESULT: " + list);
RESULT: 100, 101, 103
I don’t have a big experience on Stream API is it possible to simplify my implementation?
New contributor
Roman Chumak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.