遍历 HashSet 的方法
生活随笔
收集整理的這篇文章主要介紹了
遍历 HashSet 的方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
遍歷 HashSet 的方法
import java.util.HashSet; import java.util.Iterator; import java.util.Set;public class Test {public static void main(String[] args) {Set<String> set = new HashSet<>();set.add("Geeks");set.add("for");set.add("Geeks");System.out.println("迭代器:");for (Iterator it = set.iterator(); it.hasNext(); ) {System.out.println(it.next());}System.out.println("增強for循環(huán):");for (String str : set) {System.out.println(str);}System.out.println("forEach方法:");set.forEach((s) -> System.out.println(s));} }迭代器:
Geeks
for
增強for循環(huán):
Geeks
for
forEach方法:
Geeks
for
來源:遍歷 HashSet 的方法 - 走在修行的大街上 - 博客園
總結(jié)
以上是生活随笔為你收集整理的遍历 HashSet 的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 听说大部分商用车车型都能用华中蓄电池,长
- 下一篇: 利用PostMan 模拟上传/下载文件(