Here you can find the source of sortedArraysEqual(Object[] arr1, Object[] arr2)
Parameter | Description |
---|---|
arr1 | The first array |
arr2 | The second array |
public static boolean sortedArraysEqual(Object[] arr1, Object[] arr2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Arapiki Solutions Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww. j a v a 2 s . c o m*/ * "Peter Smith <psmith@arapiki.com>" - initial API and * implementation and/or initial documentation *******************************************************************************/ import java.util.Arrays; public class Main { /** * Determine whether two arrays contain the same elements, even if those elements * aren't in the same order in both arrays. The equals() method is used to determine * if elements are the same. * @param arr1 The first array * @param arr2 The second array * @return True if the arrays contain the same elements, else false. */ public static boolean sortedArraysEqual(Object[] arr1, Object[] arr2) { /* if one is null, then both must be null */ if (arr1 == null) { return (arr2 == null); } /* types must be the same */ if (arr1.getClass() != arr2.getClass()) { return false; } /* lengths must be the same */ if (arr1.length != arr2.length) { return false; } /* now sort the elements and compare them */ Arrays.sort(arr1); Arrays.sort(arr2); return Arrays.equals(arr1, arr2); } }