Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

import java.util.*;

public class Main {
    @SuppressWarnings({ "unchecked" })
    public static <X extends Node> List<X> getChildNodes(Node node, Class<X> type) {
        final NodeList nodelist = node.getChildNodes();
        ArrayList<X> list = new ArrayList<X>(nodelist.getLength());
        for (int i = 0; i < nodelist.getLength(); i++) {
            final Node child = nodelist.item(i);
            if (type.isInstance(child)) {
                list.add((X) child);
            }
        }
        return list;
    }
}