像这样的弦乐伴奏速度非常慢。使用StringBuilder。
@Overridepublic String toString(){ StringBuilder buffer = new StringBuilder(); printTree(this, buffer); return buffer.toString();}public void printTree(AbstractTree<E> tree, StringBuilder buffer){ if (tree.isLeaf()){ buffer.append(tree.getNodeName()); } else { buffer.append(tree.getNodeName()); buffer.append("("); int i = 0; Iterator<AbstractTree<E>> child = tree.getChildren().iterator(); while (i < tree.getChildren().size() - 1){ printTree(child.next(), buffer); buffer.append(", "); i++; } printTree(child.next(), buffer); buffer.append(")"); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)