java Arrays.equals()方法简介 |
您所在的位置:网站首页 › 远程控制别人电脑的方法有哪些软件 › java Arrays.equals()方法简介 |
简介
java Arrays中定义了如下几种equals方法,用来对比判断数组是否相等 equals(boolean[], boolean[])equals(byte[], boolean[])equals(char[], boolean[])equals(double[], boolean[])equals(float[], boolean[])equals(short[], boolean[])equals(int[], boolean[])equals(long[], boolean[])equals(Object[], boolean[]) 源码每一个方法里的源码实现基本都差不多,我们看下equals(int[], boolean[])的源码实现 代码很简单,若两个数组的长度相等,且每一个位置的元素也相等,则认为这两个数组相等 /** * Returns true if the two specified arrays of ints are * equal to one another. Two arrays are considered equal if both * arrays contain the same number of elements, and all corresponding pairs * of elements in the two arrays are equal. In other words, two arrays * are equal if they contain the same elements in the same order. Also, * two array references are considered equal if both are null.* * @param a one array to be tested for equality * @param a2 the other array to be tested for equality * @return true if the two arrays are equal */ public static boolean equals(int[] a, int[] 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 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |