使用递归调用时需要注意的问题。

1.若递归方法中存在循环,循环中反复调用递归方法时,必须注意其循环外定义的变量,每次循环都会初始为定义的变量,所以为了动态生成其外变量,一般为循环的返回值。

2.判断跳出递归方法的位置放在那里比较合适。(一般放在循环的最开始)

public static String noteReplace(Map note, StringBuilder sb){

//将Map转换为迭代器模式
Iterator> it = note.entrySet().iterator();  
StringBuilder rsb = sb;
while(it.hasNext()){
if(note.size() == 0){
break;
}
Map.Entry entry=it.next(); 
String name = entry.getValue().substring(entry.getValue().indexOf("@")+1);
int startName = sb.indexOf(entry.getValue());
int endName = startName + entry.getValue().length();
String reString = "<"+name+">"+entry.getKey()+"";
rsb = sb.replace(startName, endName, reString);
it.remove();
noteReplace(note, rsb);
}

return rsb.toString();

}

你可能感兴趣的:(工作日常问题记录)