import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public final class Main {
public static final class Node {
private final List<Node> children;
}
this(name,
Arrays.
stream(children
) .map(Node::new)
.collect(Collectors.toUnmodifiableList()));
}
private Node
(String name, List
<Node
> list
) { this.name = name;
this.children = list;
}
public List<Node> getChildNodes() {
return children;
}
@Override
return "name: " + name;
}
}
private static List<Node> getNodes() {
new Node("image", "raw", "jpeg", "png"),
new Node("video", "mp4"),
new Node("game"),
new Node("music", "wav", "mp3"));
}
private static void fixMe() {
var list = getNodes().stream()
.flatMap(n -> n.getChildNodes().stream().findFirst().stream())
.collect(Collectors.toList());
list.
forEach(System.
out::println
); }
public static void main
(String[] args
) { fixMe();
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheXM7CmltcG9ydCBqYXZhLnV0aWwuQ29sbGVjdGlvbnM7CmltcG9ydCBqYXZhLnV0aWwuTGlzdDsKaW1wb3J0IGphdmEudXRpbC5zdHJlYW0uQ29sbGVjdG9yczsKCnB1YmxpYyBmaW5hbCBjbGFzcyBNYWluIHsKCiAgICBwdWJsaWMgc3RhdGljIGZpbmFsIGNsYXNzIE5vZGUgewoKICAgICAgICBwcml2YXRlIGZpbmFsIFN0cmluZyBuYW1lOwogICAgICAgIHByaXZhdGUgZmluYWwgTGlzdDxOb2RlPiBjaGlsZHJlbjsKCiAgICAgICAgcHVibGljIE5vZGUoU3RyaW5nIG5hbWUpIHsKICAgICAgICAgICAgdGhpcyhuYW1lLCBDb2xsZWN0aW9ucy5lbXB0eUxpc3QoKSk7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgTm9kZShTdHJpbmcgbmFtZSwgU3RyaW5nLi4uIGNoaWxkcmVuKSB7CiAgICAgICAgICAgIHRoaXMobmFtZSwgQXJyYXlzLnN0cmVhbShjaGlsZHJlbikKICAgICAgICAgICAgICAgIC5tYXAoTm9kZTo6bmV3KQogICAgICAgICAgICAgICAgLmNvbGxlY3QoQ29sbGVjdG9ycy50b1VubW9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