获取数组中的重复元素
将数组这个的重复元素获取出来 在去重
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]] } }
作 者:一支会记忆的笔
---------------------
个性 签名:真正的学习不是记住知识,而是学会如何提出问题,研究问题,解决问题。
如果觉得这篇文章对你有小小的帮助的话,记得在下方“关注”哦,博主在此感谢!

浙公网安备 33010602011771号
返回顶部