Here you can find the source of arraysEqual(String[] arr1, String[] arr2)
Parameter | Description |
---|---|
arr1 | a parameter |
arr2 | a parameter |
public static boolean arraysEqual(String[] arr1, String[] arr2)
//package com.java2s; /*//from w ww . j a va 2s .c o m * JBoss, Home of Professional Open Source * * Copyright 2013 Red Hat, Inc. and/or its affiliates. * * Licensed 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. */ public class Main { /** * Match two arrays for equality * * @param arr1 * @param arr2 * @return */ public static boolean arraysEqual(String[] arr1, String[] arr2) { if (arr1 != null && arr2 == null) { return false; } if (arr1 == null && arr2 == null) { return true; } if (arr1 == null && arr2 != null) { return false; } int length1 = arr1.length; int length2 = arr2.length; if (length1 != length2) { return false; } boolean foundMatch = false; for (int i = 0; i < length1; i++) { for (int j = 0; j < length2; j++) { if (arr1[i].equals(arr2[j])) { foundMatch = true; break; } } if (foundMatch == false) { return false; } // reset foundMatch = false; } return true; } }