zoukankan      html  css  js  c++  java
  • java数组相等

    java中数组相等判断:

    1.最常规的是遍历

     public static boolean arrayEquals(String[] a,String[] b){
      boolean flag = false;
      if(a.length != b.length){
       return false;
      }else{
       for (int i = 0; i < a.length; i++) {
        System.out.println(a[i] + "	" + b[i]);
        if(!a[i].equals(b[i])){
         flag = false;
         break;
        }else{
         flag = true;
        }  
       }
      }
      return flag;
     }
        public static boolean arrayEquals(int[] a,int[] b){
              boolean flag = false;
              if(a.length != b.length){
                  return false;
              }
            for(int i = 0; i < a.length; i++) {
                System.out.println(a[i] + "	" + b[i]);
                if(a[i]!=b[i]){
                     flag = false;
                     break;
                }
                flag = true;  
            }
              return flag;
        }

    2.用Arrays.equals

    Arrays.equals(a, a2);

    //下面是 Arrays.equals方法的源码
        public static boolean equals(long[] a, long[] a2) {
            if (a==a2)
                return true;
            if (a==null || a2==null)
                return false;
            int length = a.length;
            if (a2.length != length)
                return false;
            for (int i=0; i<length; i++)
                if (a[i] != a2[i])
                    return false;
            return true;
        }
  • 相关阅读:
    Codeforces Round #456 (Div. 2)
    Codeforces Round #455 (Div. 2)
    Codeforces Round #453 (Div. 1)
    Codeforces Round #450 (Div. 2)
    退役了
    退役了
    这个博客不想要了
    Hello!The familiar and strange world.
    真正的退役了。
    bzoj4231: 回忆树
  • 原文地址:https://www.cnblogs.com/sanxinglan/p/3291718.html
Copyright © 2011-2022 走看看