要用递归
public static void showList(List
草,本来你就是递归定义。不用递归能循环出来吗?
public static void print(Menu m){
System.out.println("Menu"+m.getMenuId()+" "+m.getMenuName());
List
private String id = "";
public String getChildrenById_1(String pid) {
if(pid!=null){
this.id="-1";
this.id+=","+pid.toString();
this.getChildrenById(new Long(pid));
}
return id;
}
private void getChildrenById(Long pid){
List
for(Long cid:list){
if(cid!=null){
this.id+=","+cid;
this.getChildrenById_1(cid);
}
}
}
这只是一个思路,你自己再试着改下
public void parseMenu(Menu menu) {
System.out.println(Menu);//打印语句在实际中是对Menu展示的处理
if(menu.getChilds()!=null && menu.getChilds().size()!=0) {
for(Menu child:menu.getChilds()) {
parseMenu(child);
}
}
}
public class TestMain {
public static void main(String[] args) {
List
all.add("aaa") ;
all.add("bbb") ;
Iterator iter = all.iterator() ;
while(iter.hasNext())
{
String obj = (String)iter.next() ;
System.out.println(obj) ;
}
}
}