In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to recursive department tree in java, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Department object package com.ytx.demo.tree;import java.util.ArrayList;import java.util.List;public class Department {private int id;private String name;private int parentId;private List children = new ArrayList (); public Department (int id, String name, int parentId) {this.id = id; this.name = name; this.parentId = parentId;} public int getId () {return id;} public void setId (int id) {this.id = id } public String getName () {return name;} public void setName (String name) {this.name = name;} public int getParentId () {return parentId;} public void setParentId (int parentId) {this.parentId = parentId;} public List getChildren () {return children;} public void setChildren (List children) {this.children = children;}} recursive implementation of package com.ytx.demo.tree;import java.util.ArrayList;import java.util.List Public class DempartmentThree {public static void main (String [] args) {List departmentList = new ArrayList (); departmentList.add (new Department (1, "R & D Department", 0)); departmentList.add (new Department (2, "R & D team 1", 1)); departmentList.add (new Department (3, "R & D team 2", 1)); departmentList.add (new Department (4, "Finance Department", 0)) DepartmentList.add (new Department (5, "Finance A Department", 4); departmentList.add (new Department (6, "Finance B Department", 4)); departmentList.add (new Department (7, "Finance A Department team 1", 5)); departmentList.add (new Department (8, "Finance A Department team 2", 5); departmentList.add (new Department (9, "Finance B Department team 1", 6) DepartmentList.add (new Department (10, "Finance Department B team 2", 6); List listTree = getThree (departmentList,0); System.out.println (listTree);} private static List getThree (List list,int parentId) {/ / get all child nodes List childTreeList = getChildTree (list,parentId); for (Department dept:childTreeList) {dept.setChildren (getThree (list,dept.getId ();} return childTreeList } private static List getChildTree (List list,int id) {List childTree = new ArrayList (); for (Department dept:list) {if (dept.getParentId () = = id) {childTree.add (dept);}} return childTree;}} the above content is how to recursive department tree in java. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.