How to use org.w3c.dom.NodeList with Java 8 Stream API?
04:50 29 Apr 2014

I believe the Interface org.w3c.dom.NodeList is missing a stream() function to make use of the benefits of Java 8's Stream API. Considering the introduction of default methods to ensure backwards compatibility, I fail to understand why this Interface doesn't have stream() function.

So my questions are:

  • How do I use a NodeList in combination with the Stream API?
  • If it's discouraged to do so, what are the reasons for that?

Thanks in advance!

Edit: I'm currently using this utility wrapper:

private static Stream nodeStream(NodeList list) {
    List nodes = new ArrayList<>();

    for (int n = 0; n < list.getLength(); ++n) {
        nodes.add(list.item(n));
    }

    return nodes.stream();
}
java dom