Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Example code of JAVA recursive call

Shulou Source: shulou.com Published: 2022-06-02 08:53:18 09月22日 Update

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!

Tags: Recursion code examples problems conditions programs boundaries learning content that is complex similar generally speaking between functions objects ideas situations data articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Shulou Technology Huawei Xiaomi