Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.tree.DefaultMutableTreeNode;

public class Main {
    public static DefaultMutableTreeNode pathToTreeNode(Object[] objects) {
        return pathToTreeNode(objects, 0);
    }

    static DefaultMutableTreeNode pathToTreeNode(Object[] objects, int offset) {
        if (objects == null || objects.length == 0 || offset >= objects.length || offset < 0) {
            return null;
        }
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(objects[offset]);
        DefaultMutableTreeNode child = pathToTreeNode(objects, offset + 1);
        if (child != null) {
            node.add(child);
        }
        return node;
    }
}