1 回答
TA贡献2012条经验 获得超12个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.util.HashSet; import java.util.Iterator; import java.util.Set;
public class SetTest { //结果输出为ELEM static void AddToSet(){ String str = "ELEM"; String str1 = new String("ELEM"); Set set = new HashSet(); Set setCompare = new HashSet(); set.add(str); set.add(str1); setCompare.add(str1); //Iterator是用来遍历容器中的元素的 Iterator itera = set.iterator(); Iterator iteraCompare = setCompare.iterator(); while(itera.hasNext()) { System.out.println((String)itera.next()); } while(iteraCompare.hasNext()) { System.out.println((String)iteraCompare.next()); } if(set.equals(setCompare)){ System.out.println("两个对象内容相同"); } if(set == setCompare){ System.out.println("两个对象相等"); }
} public static void main(String[] args){ SetTest.AddToSet(); }
} |
- 1 回答
- 0 关注
- 897 浏览
添加回答
举报