Skip to content
Advertisement

Create list of objects from another list by using java8 stream

I have a list student list A and I have student list B.

Student objects contains some fields like that : no,age,city,birth_date,salary

My list A contains these objects

JavaScript

My list B contains these objects

JavaScript

What i want to do is extract student objects that ListA have but listB not and ListA and ListB have(as no,age,city) but salary is different.Also I want to write salary diff.

JavaScript

I want to use stream api in java 8.First of all , I want to extract students objects to a list but I can extract common student objects now.I tried tu use noneMatch but it is not working.Do you have any idea?

JavaScript

Advertisement

Answer

I used custom Collector object, looks not very nice but it seems working:

JavaScript
Advertisement