Here you can find the source of coalesce(String... strings)
Parameter | Description |
---|---|
strings | Any number of strings |
public static String coalesce(String... strings)
//package com.java2s; public class Main { /**/*w w w . j ava2s.c o m*/ * Same as the SQL COALESCE. Will get first non empty value and return it. * * @param strings Any number of strings * @return The first non empty string */ public static String coalesce(String... strings) { for (String s : strings) { if (!isEmpty(s)) { return s; } } return ""; } /** * @param s * @return true if s is null, empty or purely whitespace */ public static boolean isEmpty(String s) { return s == null || s.trim().length() == 0; } }