获取数组中的重复元素


将数组这个的重复元素获取出来  在去重

public static void main(String[] args) {
    
        String str = "xx@xx.com,aa@aa.com,aa@aa.com,nn@aa.com,xx@aa.com,xx@xx.com"
        String[] arr = str.split(",")
        System.out.println("arr: " + arr);  //arr: [xx@xx.com, aa@aa.com, aa@aa.com, nn@aa.com, xx@aa.com, xx@xx.com]

        Set listAll = new LinkedHashSet<String>()
// 获取数组重复的元素
for (int i = 0; i < arr.length; i++) { //System.out.println("arr: " + arr[i]); int curr = i; for (int j = 0; j < arr.length; j++) { if (arr[j] == arr[i] && i != j) { // System.out.println("solution1: " + arr[i]) listAll.addAll(arr[i]) } } } System.out.println("listAll: " + listAll) //listAll: [xx@xx.com, aa@aa.com] } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM