I want to build a JSON from two lists. I need to use the corresponding elements from both lists to create a single JSON object.
My problem could be solved with ordinary loop like this:
List<Class1> items = baseManager.findObjectsByNamedQuery(Class1.class, "Class1.findAll", new Object[]{});
for(int i=0 ; i<items.size();i++){
List<Class2> items2 = baseManager.findObjectsByNamedQuery(Class2.class, "Class2.findByCreatedBy" ,new Object[] {items.get(i).getCreatedBy()});
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
JsonObjectBuilder jpb = Json.createObjectBuilder()
.add("createdBy",items.get(i).getCreatedBy())
.add("phone",items2.get(0).getPhone())
groupsBuilder.add(jpb);
}
Is it possible to solve it using Java 8 Stream API?