不明白?
String a[]="asb"???我想你的意思是不是判断类似String str[20] = {"1","2",..."a"};里面是不是有重复的?public boolean checkString(String[] str){
if(str==null||str.length==0)
    return true;
HashMap map1 = new HashMap();
for(int 1 = 0 ; i < str.length; i++)
{
    if(str[i]==null)
        continue;
    else
    {
        if(map1.get(str[i])!=null)
            return false;
        else
            map1.put(str[i],str[i]);
    }
}
return true;
}

解决方案 »

  1.   

    比如:
    String [] a="name";
    Stirng [] b="sex";
    ......
    ...
    判断20个字符串。看看是否相同。就可以了。如果没有输入,就是空的,不用判断!!很麻烦的。。
      

  2.   

    老大姐,字符串是这么写的:
    String a="name";
    你那么写编译不通过的。你说不清楚问题,我只好猜了。另,你把他们都放到一个数组里不就行了?
    String[] str = new String[20];
    str[0] = a;
    str[1] = b;
    ...
    str[19] = z;
    再比较啊,不会你想传20个参数过去吧?不过真的传20个参数也可以象我那样比较啊。
      

  3.   

    public static boolean checkString(String[] str) {
        if (str == null || str.length == 0)
            return true;
        java.util.HashMap map1 = new java.util.HashMap();
        for (int i = 0; i < str.length; i++) {
            if (str[i] == null)
                continue;
            else {
                if (map1.get(str[i]) != null)
                    return false;
                else
                    map1.put(str[i], str[i]);
            }
        }
        return true;
    }
    改成静态的方便直接调用。还有刚才写错了个字,呵呵。
      

  4.   

    哥们,不对啊始终返回false!!!
      

  5.   

    楼主,是不是跑错地方了,java中字符串是对象,不是数组
      

  6.   

    楼主姐们阿姨
    你欺骗我幼小纯洁的心灵
        String[] s = new String[20];
        for (int i = 0; i < 20; i++) {
            s[i] = "" + i;
            System.out.println(s[i]);
        }
        System.out.println(checkString(s));
    结果:
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    true
    哪里错了?
      

  7.   

    这个checkString有用?put完了之后,总是返回true的吧。我觉得???
      

  8.   

    哥们,,,对不起,刚才我错了。。
    你请解释:
    为什么;
    String a="xxx";
    String b="yyy";
    String[] str={a,b}
    编译没错,,,
    String a="xxx";
    String b="yyy";
    String[] str={}
    str={a,b}就错了,,,为什么,,
     relive高手,,请解释你写的HashMap原理!!谢谢!!
      

  9.   

    是不是
    return map1.size()==str.length?
      

  10.   

    str={a,b}要这么写
    str = new String[]{a,b};HashMap是Java自身的散列表,不是我写的
      

  11.   

    flyinrain(追雨鸟)拜托大哥我有写
    return false;

    return map1.size()==str.length也可以,不过会有冗余,效率底那么点点。
      

  12.   

    String a="xxx";
    String b="yyy";
    String[] str={a,b}
    编译没错,,,
    String a="xxx";
    String b="yyy";
    String[] str={}
    str={a,b}就错了,,,为什么,,
    所以说你跑错了地方,java不是c/c++String[] str=new String[2];
    str[0]=a; str[1]=b;
    其实数组也是对象,也要new初始化
      

  13.   

    public  boolean judge_name() {
          String a1="cd";
          String a2="sw";
          String a3="fa";      String[] str={a1,a2,a3};
          if (str == null || str.length == 0)
              return true;
          java.util.HashMap map1 = new java.util.HashMap();
          for (int i = 0; i < str.length; i++) {
              if (str[i] == null)
                  continue;
              else {
                  if (map1.get(str[i]) != null)
                      return false;
                  else
                      map1.put(str[i], str[i]);
              }
          }
          return true;
      }无论你给a1,a2,a3给什么数,都返回false..我调试了,,,
      

  14.   

    怎么可能?
    public static void main(String[] arg1) {
        System.out.println(judge_name());
    }
    public static boolean judge_name() {
        String a1 = "cd";
        String a2 = "sw";
        String a3 = "fa";    String[] str = { a1, a2, a3 };
        if (str == null || str.length == 0)
            return true;
        java.util.HashMap map1 = new java.util.HashMap();
        for (int i = 0; i < str.length; i++) {
            if (str[i] == null)
                continue;
            else {
                if (map1.get(str[i]) != null)
                    return false;
                else
                    map1.put(str[i], str[i]);
            }
        }
        return true;
    }
    我打印出来是
    true
      

  15.   

    555555555555555555555。非常抱歉刚才不知道怎么的,程序没有关完嘛??始终运行的是以前的所有出错。特地向各位道歉,特别是 relive(大哥!!!】我想说。csdn因为有你们而精彩!!!
      

  16.   

    relive(大哥,真的,很抱歉,,,
    我计算机是2*256的内存,,,运行很快的,不知道怎么的,,,每次运行都是以前的程序。。
    有鬼。。真的,,
    今晚上非常谢谢你 !!!你太好了,有一天我会何你一样热心帮助别人的。再次谢谢你!!
      

  17.   

    要不就小弟啊。^_^。。
    补充算法:如下:
     for (int i = 0; i < str.length; i++) {
              if (str[i] == null)
                  continue;
              else if (str[i].length()==0)
                continue;
              else {
                  if (map1.get(str[i]) != null)
                      return false;
                  else
                      map1.put(str[i], str[i]);
              }
          }因为如果没有输入 else if (str[i].length()==0)           continue;
    也必须判断,,,大哥是不是。^_^。谢谢你,
    来大连我请客!!真的!