Streams API :: How do i modify the variables of my custom object from a LIST<Object>?

Rajat Diwate :

1.I am getting a List of Objects form Database Containing Fields as per my pojo.. List fieldList==>Contains the List of Objects...>

List<Object> fieldList;
for(Object abc: fieldList){
                    abc.setIdMongoStr("RoleName");
                    abc.setTenantRegion("RoleNumber");
                }

How do i convert it Stream ????

Constantin Trepadus :

if you need to set the same value to each item and thats all, you can use directly foreach, here is an example:

fieldList.stream().forEach(field -> {
            field.setIdMongoStr("RoleName");
            field.setTenantRegion("RoleNumber");
        });

This will mutate directly your objects inside the list

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27080&siteId=1
Recommended