java 8 - Collect a List from another List in Java8 using streams -
i have list of objects. want move through list , collect few objects need , create list of objects. how can achieve in java8.
i start transactions.gettransactions()
returns arraylist. now, want create list of transactions
using t.getid()
, t.getname()
, t.getdate()
. how can make null checks objects t.getotheraccount().getholder().getcountrerpartyname() efficiently..
transrolist.addall(trans.stream().filter(t -> t.getdetails().gettransactiontype() != null) .filter(t -> t.getdetails().gettransactiontype().equals(type)) .map(t -> { transactionsro ro = new transactionsro(); ro.setid(t.getid()); ro.setaccountid(t.getthisaccount().getaccountid()); ro.setcounterpartyaccount(t.getotheraccount().getcounterpartyaccount()); ro.setcounterpartylogopath(t.getmetadata() != null ? t.getmetadata().getcounterpartylogopath() : null); ro.setcounterpartyname(t.getotheraccount().getholder().getcounterpartyname()); ro.setdescription(t.getdetails().getdescription()); ro.setinstructedamount(t.getdetails().getvalue().gettransactionamount()); ro.setinstructedcurrency(t.getdetails().getvalue().gettransactioncurrency()); ro.settransactionamount(t.getdetails().getnewbalance() !=null ? t.getdetails().getvalue().gettransactionamount() : null); ro.settransactioncurrency(t.getdetails().getnewbalance() !=null ? t.getdetails().getvalue().gettransactioncurrency() : null); ro.settransactiontype(t.getdetails().gettransactiontype()); return ro; }).collect(collectors.tolist()));
Comments
Post a Comment