Here you can find the source of max(final String string1, final String string2)
Parameter | Description |
---|---|
string1 | the string 1 |
string2 | the string 2 |
public static String max(final String string1, final String string2)
//package com.java2s; /*/* w w w . j ava 2 s . c o 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 max(final String string1, final String string2) { if (string1 == null) { return string2; } else if (string2 == null) { return string1; } return string1.length() > string2.length() ? string1 : string2; } }