I started learning Stream API, but can't make through this one.
I'm implementing graphs, so I have classes like so:
Graph -> Node -> Edge
Nodes in graph are stored in Hashset; Edges in Nodes too.
Here's code:
Graph g = new Graph("Graph 1");
g.addNode(new Node("A"));
g.addNode(new Node("B"));
g.connectNodes("A","B", true); //nodeA, nodeB, bidirectional
System.out.println(g);
g.getNodes().stream().map(Node::getConnections);
I dunno what do next with last line. At this moment it returns HashSet of edges.
I tried
g.getNodes().stream().map(Node::getConnections).map(x->x.getNodeB().getName()).forEach(System.out::println);
to get second connected via edge node name, but IDE don't allow me to do next map.
Can you give some hints?
flatMapinstead.flatMap(node -> node.getConnections().stream())- Sergii Bishyr