java 判断一个数组是否有重复值

来源:互联网 发布:软件开发项目收获 编辑:程序博客网 时间:2024/06/06 11:47
import java.util.HashSet;public class test {    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        int[] array = { 1, 2, 3, 4, 6, 6, 7, 8, 9 };        if (cheakIsRepeat(array)) {            System.out.println("没有重复值!");        } else {            System.out.println("有重复值!");        }    }    /*     * 判断数组中是否有重复的值     */    public static boolean cheakIsRepeat(int[] array) {        HashSet<Integer> hashSet = new HashSet<Integer>();        for (int i = 0; i < array.length; i++) {            hashSet.add(array[i]);        }        if (hashSet.size() == array.length) {            return true;        } else {            return false;        }    }}
0 0
原创粉丝点击