日期:2014-05-20 浏览次数:20671 次
public class TreeTest { public static void main(String[] args) { Set<TreeVo> tree = new TreeSet<TreeVo>(); TreeVo vo1 = new TreeVo(1,2); TreeVo vo2 = new TreeVo(2,3); TreeVo vo3 = new TreeVo(3,1); if(addTree(tree, vo1)){ tree.add(vo1); } if(addTree(tree, vo2)){ tree.add(vo2); } if(addTree(tree, vo3)){ tree.add(vo3); } } public static boolean addTree(Set tree,TreeVo vo){ if(tree.contains(vo)){ System.out.println("its fail because exit:"+ vo.getNext()); return false; }else{ System.out.println("its ok:" + vo.getNext()); return true; } } }