Here you can find the source of areEqual(String string1, String string2)
Parameter | Description |
---|---|
string1 | a String instance to compare. May be null. |
string2 | a String instance to compare. May be null. |
public static boolean areEqual(String string1, String string2)
//package com.java2s; /*//from w w w . j a v a 2 s. c om Copyright 2004-2008 Strategic Gains, Inc. 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 { /** * Checks two string instances for equality, allowing for null in either or * both strings. If both strings are null, they are considered equal. * * @param string1 a String instance to compare. May be null. * @param string2 a String instance to compare. May be null. * @return true if the String instances are lexically equal. Otherwise * false. * @see compareTo(String, String) */ public static boolean areEqual(String string1, String string2) { return (compareTo(string1, string2) == 0); } /** * Compares two String instances, allowing null in either or both strings. * If both strings are null, they are considered equal. If only one string * is null, the non-null string is considered greater. If both strings are * non-null, this method returns the results of string1.compareTo(string2). * * @param string1 a String instance to compare. May be null. * @param string2 a String instance to compare. May be null. * @return <0 if string1 < string2, 0 if string1.equals(string2), >0 if * string1 > string2. */ public static int compareTo(String string1, String string2) { int result = 0; if (string1 != null && string2 == null) result = 1; else if (string1 == null && string2 != null) result = -1; else if (string1 != null && string2 != null) result = string1.compareTo(string2); return result; } }