Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate List in java 8 and invoke another function while iteration

Tags:

java

java-8

I am new to java 8.

me want to use java8 and want to convert below to java8.

List<Model> listModel;
for (Model model : listModel) 
        {
            try
            {
                new UpDateData().bankData(model.getCust_id(), model.getBank_id(), model.getDate());
            }
            catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

        }

Model class::

public class Model 
{
    private  int cust_id;
    private  int bank_id;
    private  String date;
    //setter and getter
}

My question How me can apply java 8 features on above list, me want to iterate and call teh another function.

like image 790
Pankaj Sethiya Avatar asked Jan 30 '23 04:01

Pankaj Sethiya


1 Answers

you could just use a forEach:

listModel.forEach(model -> {
    try {
        new UpDateData().bankData(model.getCust_id(), model.getBank_id(), model.getDate());
    } catch(){
         .... handle
    }
})
like image 170
Eugene Avatar answered Feb 02 '23 11:02

Eugene