Here you can find the source of coalesce(String[] values)
Parameter | Description |
---|---|
values | a parameter |
public static String coalesce(String[] values)
//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); } }