Java Type Coalesce coalesce(String[] values)

Here you can find the source of coalesce(String[] values)

Description

Returns first not null && not empty String from String[]

License

Open Source License

Parameter

Parameter Description
values a parameter

Return

first not null && not empty String

Declaration

public static String coalesce(String[] values) 

Method Source Code

//package com.java2s;
/*/* ww  w. j  av  a  2 s . c  o m*/
 * CDDL HEADER START
 * 
 * The contents of this file are subject to the terms of the Common Development and Distribution
 * License, Version 1.0 only (the "License"). You may not use this file except in compliance with
 * the License.
 * 
 * You can obtain a copy of the license at license/ESCIDOC.LICENSE or
 * http://www.escidoc.org/license. See the License for the specific language governing permissions
 * and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL HEADER in each file and include the License
 * file at license/ESCIDOC.LICENSE. If applicable, add the following below this CDDL HEADER, with
 * the fields enclosed by brackets "[]" replaced with your own identifying information: Portions
 * Copyright [yyyy] [name of copyright owner]
 * 
 * CDDL HEADER END
 */

public class Main {
    /**
     * Returns first not null && not empty String from String[]
     * 
     * @param values
     * @return first not null && not empty String
     */
    public static String coalesce(String[] values) {
        for (String val : values)
            if (checkLen(val))
                return val;
        return null;
    }

    /**
     * Returns true if val is not null && Length >0
     * 
     * @param val
     * @return first not null && Length >0
     */
    public static boolean checkLen(String val) {
        return (val != null && val.length() > 0);
    }
}

Related

  1. coalesce(Object... items)
  2. coalesce(String str1, String str2)
  3. coalesce(String... strings)
  4. coalesce(String... strings)
  5. coalesce(String... vals)
  6. coalesce(T a, T b)
  7. coalesce(T o0, T o1)
  8. coalesce(T preferred, T alternative)
  9. coalesce(T value, T whenNullValue)