HashSet内的元素遍历
import java.util.Set; import java.util.HashSet; import java.util.Iterator; public class SetTest { public static void main(String[] args) { Set<String> setExample = new HashSet<String>(); setExample.add("aaa"); setExample.add("bbb"); setExample.add("ccc"); //利用collection的Iterator遍历 Iterator iterator = setExample.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } //或者这样 for (String str:setExample ) { System.out.println(str); } } } ———————————————— 转自CSDN博客 原文链接:https://blog.csdn.net/u011402596/java/article/details/38523443