在各自岗位上尽职尽责,无需豪言壮语,默默行动会诠释一切。这世界,虽然没有绝对的公平,但是努力就会增加成功和变好的可能性!而这带着未知变量的可能性,就足以让我们普通人拼命去争取了。
欢迎来到~一支会记忆的笔~博客主页

获取数组中的重复元素

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

public static void main(String[] args) {
    
        String str = "[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]"
        String[] arr = str.split(",")
        System.out.println("arr: " + arr);  //arr: [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]]

        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: [[email protected], [email protected]] } }

 

posted @ 2020-02-20 10:18  一支会记忆的笔  阅读(1099)  评论(0)    收藏  举报
返回顶部
【学无止境❤️谦卑而行】