StringBuffer和String
public String getExits() {
/*String ret = "";
if(southExit != null)ret += southExit;
if(eastExit != null)ret += eastExit;
if(nouthExit != null)ret += nouthExit;
if(westExit != null)ret += westExit; */
//上面代码系统开销大,应使用stringbuffer
StringBuffer sb = new StringBuffer();
if(southExit != null)sb.append("south");
if(eastExit != null)sb.append("east");
if(northExit != null)sb.append("north");
if(westExit != null)sb.append("west");
return sb.toString();
}