Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example code of JAVA recursive call

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "JAVA recursive call example code", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "JAVA recursive call example code"!

1. Recursion

Recursion is a method in which a program or function is defined or stated to call itself indirectly or indirectly. It usually transforms a large and complex problem into a smaller problem that is similar to the original problem. The recursive strategy requires only a small number of programs to describe the repeated calculations needed in the problem-solving process, which greatly reduces the amount of code of the program. The ability of recursion is to define an infinite set of objects with finite statements. generally speaking, recursion requires boundary conditions, recursive forward segments and recursive return segments, recursive forward when the boundary conditions are not satisfied, and recursive returns when the boundary conditions are satisfied.

2. Instance code

Private List buildTree (List hkFiletypes, String preentId List hktrees) {/ / first-level data if ("0" .equals (preentId)) {hkFiletypes.forEach (hkFiletype-> {String parentfiletypeid = hkFiletype.getParentfiletypeid ()) If (null! = parentfiletypeid & & parentfiletypeid.equals (preentId)) {hktrees.add (hkFiletype);}}) } else {hktrees.forEach (hkFiletype-> {String id = hkFiletype.getId (); List hktree = new ArrayList ()) HkFiletypes.forEach (hkFiletype1-> {String parentfiletypeid = hkFiletype1.getParentfiletypeid (); if (parentfiletypeid.equals (id)) {hkFiletype.setHasChildren (true)) Hktree.add (hkFiletype1); buildTree (hkFiletypes,hkFiletype1.getId (), hktree);}}); hkFiletype.setChiles (hktree) });} return hktrees;}

3. Code call

Public List selectTreeList (HkFiletype hkFiletype) {hkFiletype.setDelmark (1); List hkFiletypes = hkFiletypeMapper.selectList (hkFiletype); List hktrees = new ArrayList (); hktrees = buildTree (hkFiletypes, "0", hktrees); hktrees = buildTree (hkFiletypes, "1", hktrees); return hktrees } Thank you for your reading. the above is the content of "instance Code of JAVA Recursive call". After the study of this article, I believe you have a deeper understanding of the instance code of JAVA recursive call, and the specific usage 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report