code: public static <T> List<T> toList(final NodeList nodes) {
          final List<T> res = new ArrayList<>(nodes.getLength());
          for (int i = 0; i < nodes.getLength(); i++) {
              res.add((T) nodes.item(i));
          }
          return res;
      }
docs: Convert DOM NodeList to List.