集册 Java实例教程 看看两个数组片是否相同。

看看两个数组片是否相同。

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

620
看看两个数组片是否相同。

/**

 * Licensed to the Apache Software Foundation (ASF) under one or more

 * contributor license agreements.  See the NOTICE file distributed with

 * this work for additional information regarding copyright ownership.

 * The ASF licenses this file to You under the Apache License, Version 2.0

 * (the "License"); you may not use this file except in compliance with

 * the License.  You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 *///N o w  J a v a  . c o m

//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        char[] left = new char[] { 'b', 'o', 'o', 'k', '2', 's', '.', 'c',

                'o', 'm', 'a', '1', };

        int offsetLeft = 2;

        char[] right = new char[] { 'b', 'o', 'o', 'k', '2', 's', '.', 'c',

                'o', 'm', 'a', '1', };

        int offsetRight = 2;

        int length = 2;

        System.out.println(equals(left, offsetLeft, right, offsetRight,//时代Java公众号 - N o w J a  v a . c o m 提 供

                length));

    }


    /**

     * See if two array slices are the same.

     *

     * @param left        The left array to compare

     * @param offsetLeft  The offset into the array.  Must be positive

     * @param right       The right array to compare

     * @param offsetRight the offset into the right array.  Must be positive

     * @param length      The length of the section of the array to compare

     * @return true if the two arrays, starting at their respective offsets, are equal

     * 

     * @see java.util.Arrays#equals(char[], char[])

     */

    public static boolean equals(char[] left, int offsetLeft, char[] right,

            int offsetRight, 
展开阅读全文