嵌套用户定义数据类型的for循环

时间:2018-09-26 08:32:09

标签: java loops recursion nested

您好,我正在遍历用户定义的列表类型。是否可以递归地编写此代码?请帮我递归地重写它。

       for (Tag tag : arpackages) {
           List<Tag> arpackage = tag.getChildren();
           for (Tag tag1 : arpackage) {
               List<Tag> packages = tag1.getChildren();
               for (Tag tag2 : packages) {
                   List<Tag> pack = tag2.getChildren();
                   for (Tag tag3 : pack) {
                      List<Tag> elements = tag3.getChildren();
                      for (Tag tag4 : elements) {
                        List<Tag> featureSelectionSet=tag4.getChildren(tagName);
                        if (featureSelectionSet.size() > 0) {
                             return featureSelectionSet;
                         }
                       }
                    }
                 }
              }
           }

0 个答案:

没有答案