Java Number Min Value min(final String string1, final String string2)

Here you can find the source of min(final String string1, final String string2)

Description

Returns the shortest string.

License

Apache License

Parameter

Parameter Description
string1 the string 1
string2 the string 2

Return

the shortest string

Declaration

public static String min(final String string1, final String string2) 

Method Source Code

//package com.java2s;
/*/*from   www.j ava 2s  . co m*/
 * 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 {
    /**
     * Returns the shortest string. In case one string is null, the other string will be returned
     *
     * @param string1 the string 1
     * @param string2 the string 2
     * @return the shortest string
     */
    public static String min(final String string1, final String string2) {
        if (string1 == null) {
            return string2;
        } else if (string2 == null) {
            return string1;
        }
        return string1.length() > string2.length() ? string2 : string1;
    }
}

Related

  1. min(final int a, final int b)
  2. min(final int a, final int b)
  3. min(final Iterable numbers)
  4. min(final NUMBER_TYPE n1, final NUMBER_TYPE n2)
  5. min(final NUMBER_TYPE number1, final NUMBER_TYPE number2)
  6. min(float a, float b)
  7. min(float a, float b)
  8. min(float a, float b, float c, float d, float e)
  9. min(float dirOffset, float min, float max)