List<Person> personsInOMwithTypeDsc = personsInOm.stream()
.filter(e -> e.getPersonType().getPersonTypeId() ==1 )
.forEach(personTypeList.stream()
.foreach(d -> d.getPersonTypeId() == 1 )
.map(Person::setPersonType(d))
.collect(Collectors.toList());
I want to assign a value to a variable in the first object if the condition in the inner loop matches. Is that possible in java streams ?
Without knowing much about your types...
List<Person> persons = /*you're getting this from somewhere*/;
persons.stream()
.filter(person -> person.isSatisfiedByYourConditon())
.forEach(person -> person.setSomeField("new value"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.