Prepare new list based on conditions from two object lists using stream
I am working in spring boot application, working with lists.
I have these classes :
public class MyModel {
private String pptId;
private String pptTitle;
private String modelNumber;
}
public class FullData {
private String pptTitle;
private String modelNumber;
private String pptDetails;
private String price;
...............
..............
}
List sourceModelList = This is full list
MyModel(1,'ppt1','a1')
MyModel(1,'ppt1','a2')
MyModel(2,'ppt2','a1')
MyModel(2,'ppt2','a3')
MyModel(2,'ppt2','a4')
MyModel(3,'ppt3','a1')
MyModel(3,'ppt3','a3')
MyModel(3,'ppt3','a5')
I have filtered FullData list but that is filtered from some processing
List filteredFullDataList = it is unique list
FullData(null,'a1','pptDetails1','300')
FullData(null,,'a2','pptDetails21','70')
FullData(null,,'a4','pptDetails41','10')
FullData(null,'a5','pptDetails13','45')
Now I need to set the title and prepare list as in the order it present in sourceArticleList, only I have to remove non-existing modelNumber which is not present in filteredFullDataList as a3. But I need repeated models as they are presented in another ppt.
We need final list of FullData as :
FullData('ppt1','a1','pptDetails1','300')
FullData('ppt1',,'a2','pptDetails21','70')
FullData('ppt2','a1','pptDetails1','300')
FullData('ppt2','a4','pptDetails41','10')
FullData('ppt3','a1','pptDetails1','300')
FullData('ppt5','a5','pptDetails13','45')
I have tried streams and processed by seeting slide then preparing the FullData object and it's list, but it not working properly.
I need this below code into streams
List<FullData> finalFullData = new ArrayList();
for (MyModel myModel : sourceModelList) {
for (FullData fullData : filteredFullDataList) {
if (myModel.getModelNumber().equals(fullData.getModelNumber())) {
fullData.setPptTitle(myModel.setPptTitle());
finalFullData.add(fullData);
}
}
}
from Recent Questions - Stack Overflow https://ift.tt/Y6Djcb9OH
https://ift.tt/Mhf8FyP6J
Comments
Post a Comment