how to print set in java

纯净搜索 为您找到 本页 4 条,用时 0 秒(数据源:bingrss)

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 使用 `System.out.println()` 直接打印:

Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(3);
System.out.println(set);

2. 使用迭代器遍历并打印:

Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(3);
for (Integer num : set) {
System.out.println(num);
}

3. 使用增强型for循环打印:

Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(3);
for (Integer num : set) {
System.out.println(num);
}

小红书

Redirecting to /explore.
xiaohongshu.com

rednote (小红书) - global lifestyle hub

Welcome to the rednote community! Discover what people are cooking, wearing, and listening to around the world. Share a travel tip, a glimpse of your home, or a photo of your pet. A small moment from your day could spark a conversation or help someone trying something new.
rednote.com

打开小红书

Discover and download the Xiaohongshu App to explore lifestyle tips, product reviews, and community stories.
oia.xiaohongshu.com

小红书 - Windows官方下载 | 微软应用商店 | Microsoft Store

欢迎来到小红书,这里是你专属的生活兴趣社区! 在这里,热爱闪闪发光,好奇找到回响,一起来开启属于你的兴趣宇宙吧! 发现精彩:世界那么大,兴趣那么多! 无数和你一样充满好奇心的人,在这里分享着他们的热爱与探索。
apps.microsoft.com