Here you can find the source of getSubTree(TreeNode root, String name)
Parameter | Description |
---|---|
root | the root |
name | the name |
public static TreeNode getSubTree(TreeNode root, String name)
//package com.java2s; //License from project: Open Source License import javax.swing.tree.TreeNode; public class Main { /**//from w w w. j av a 2 s . co m * find a subtree in the root node and return it, based on exact match. * * @param root the root * @param name the name * @return the sub tree */ public static TreeNode getSubTree(TreeNode root, String name) { // if root is what we are looking for, get it if (("" + root).equals(name)) return root; // else go into children (depth-first) TreeNode node = null; for (int i = 0; i < root.getChildCount(); i++) { node = getSubTree(root.getChildAt(i), name); if (node != null) break; } return node; } }