集册 Java实例教程 比较两个短数组。

比较两个短数组。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

516
比较两个短数组。


//package com.nowjava;


public class Main {/*n o w    j a v a  . c o m 提供*/

    /**

     * Compare two short arrays. No null checks are performed.

     * 

     * @param left

     *            the first short array

     * @param right

     *            the second short array

     * @return the result of the comparison

     */

    public static boolean equals(short[] left, short[] right) {

        if (left.length != right.length) {

            return false;

        }

        boolean result = true;

        for (int i = left.length - 1; i >= 0; i--) {

            result &= left[i] == right[i];

        }

        return result;/*时 代 J a v a 公 众 号 提供*/

    }


    /**

     * Compare two two-dimensional short arrays. No null checks are performed.

     * 

     * @param left

     *            the first short array

     * @param right

     *            the second short array

     * @return the result of the comparison

     */

    public static boolean equals(short[][] left, short[][] right) {

        if (left.length != right.length) {

            return false;

        }

        boolean result = true;

        for (int i = left.length - 1; i >= 0; i--) {

            result &= equals(left[i], right[i]);

        }

        return result;

    }


    /**

     * Compare two three-dimensional short arrays. No null checks are performed.

     * 

     * @param left

     *            the first short array

     * @param right

     *            the second short array

     * @return the result of the comparison

     */

    public static boolean equals(short[][][] left, 
展开阅读全文