JAVA 字符或数组判断是否包含重复值

@Test
    public void test(){
        String a="a,b,c,d,e,f,g,h,a,c,d,e";
        String b[]=a.split(",");
        String temp = "";
        for (int i = 0; i < b.length- 1; i++)
        {
            temp = b[i];
            for (int j = i + 1; j < b.length; j++)
            {
                if (temp.equals(b[j]))
                {
                    System.out.println("第" + (i + 1) + "个跟第" + (j + 1) + "个重复,值是:" + temp);
                }
            }
        }
    }

猜你喜欢

转载自blog.csdn.net/songanshu/article/details/81563781
今日推荐