In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the application of list tree transformation in Java". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the application of list tree transformation in Java".
Public class TreeNode {private String id; private String parentId; private String name; private List children; public TreeNode (String id, String name, String parentId) {this.id = id; this.parentId = parentId; this.name = name;} public TreeNode (String id, String name, TreeNode parent) {this.id = id; this.parentId = parent.getId (); this.name = name } public String getParentId () {return parentId;} public void setParentId (String parentId) {this.parentId = parentId;} public String getName () {return name;} public void setName (String name) {this.name = name;} public String getId () {return id;} public void setId (String id) {this.id = id } public List getChildren () {return children;} public void setChildren (List children) {this.children = children } @ Override public String toString () {return "TreeNode {" + "id='" + id +'\'+ ", parentId='" + parentId +'\'+ ", name='" + name +'\'+ ", children=" + children +'}' }} public class TreeBuilder {/ * two-layer Loop implementation Tree Construction * @ param treeNodes list of incoming tree nodes * @ return * / public static List bulid (List treeNodes) {List trees = new ArrayList (); for (TreeNode treeNode: treeNodes) {if ("0" .equals (treeNode.getParentId () {trees.add (treeNode) } for (TreeNode it: treeNodes) {if (it.getParentId () = = treeNode.getId ()) {if (treeNode.getChildren () = = null) {treeNode.setChildren (new ArrayList ());} treeNode.getChildren () .add (it) } return trees;}} Thank you for your reading, the above is the content of "the application of list tree conversion in Java". After the study of this article, I believe you have a deeper understanding of the application of list tree conversion in Java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.