我的github
posts - 3243,  comments - 42,  views - 158万

在Java中,可以使用Set接口的实现类来创建一个不重复的列表。Set接口不允许重复元素,因此可以保证列表中的元素不重复。

复制代码
import java.util.HashSet;
import java.util.Set;
public class Main {
    public static void main(String[] args) {
        Set uniqueList = new HashSet<>();
        
        uniqueList.add("Apple");
        uniqueList.add("Banana");
        uniqueList.add("Apple"); // 重复元素,不会被添加
        
        System.out.println(uniqueList); // 输出 [Apple, Banana]
    }
}
复制代码

参考:https://sg-info.cn/article/show/14666

posted on   XiaoNiuFeiTian  阅读(998)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2022-01-05 ArcGIS GP选项设置
2021-01-05 arcgis显示问题:点挤在一起了(ArcGIS还可以,但是ArcGIS Server切片太糟糕了)-抽稀&聚类Cluster
2021-01-05 Arcgis空间连接(Spatial Join)
2020-01-05 pytorch训练模型
2020-01-05 如何有效使用Pretrained Models
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示