Rewrite function in java-8 style -
i implement next task in 1 stream, without loop in code:
public list<integer> findsumforeachnode() { list<integer> result = new arraylist<>(); (int ind = 0; ind < nodenum; ind++) { result.add(stream .concat(getneighbors(ind).stream(), getinneighbors(ind).stream()) .collect(summingint(integer::intvalue))); } return result; } what going on: each node take neighbours (list) , inneighbours(list), find sum , add result in result list.
intstream.range(0, nodenum) .maptoobj(ind -> stream.concat( getneighbors(ind).stream(), getinneighbors(ind).stream()) .collect(summingint(integer::intvalue))) .collect(tolist());
Comments
Post a Comment