zoukankan      html  css  js  c++  java
  • 查找重复元素

    /**
     * 查找重复元素
     * @author 华伟科技
     */
    public class Demo {
    	public static void main(String[] args) {
    		int[] my_array = { 1, 2, 5, 5, 6, 6, 7, 2, 9, 2 };
    		findDupicateInArray(my_array);
    	}
    	public static void findDupicateInArray(int[] a) {
    		int count = 0;
    		for (int j = 0; j < a.length; j++) {
    			for (int k = j + 1; k < a.length; k++) {
    				if (a[j] == a[k]) {
    					count++;
    				}
    			}
    			if (count == 1) {
    				System.out.println("重复元素 : " + a[j]);
    			}
    			count = 0;
    		}
    	}
    }

    public static void main(String[] args) {
            String[] str = { "Z", "H", "A", "N", "G", "H", "O", "N", "G", "W", "E", "I"};
            List<String> list = new ArrayList<String>();    
            for (int i=0; i<str.length; i++) {    
                if(!list.contains(str[i])) {    
                    list.add(str[i]);    
                }    
            }    
    		for (int i = 0; i < list.size(); i++) {
    			System.out.println(list.get(i));
    		}
        }
    

      


      

  • 相关阅读:
    JS数组分页
    UI框架
    mongodb
    koa2 router中间件的三种写法
    Float浮点数转二进制串和十六进制串
    Iterator和for...of循环
    mysql相关故障
    lsof
    iostat测试磁盘性能
    dd测试磁盘
  • 原文地址:https://www.cnblogs.com/hongwei2085/p/12370194.html
Copyright © 2011-2022 走看看