// some or all may be empty // remove empty ones, surround the rest with parentheses, and join with " AND " public static String joinSubqueries(String... subqueries) { List<String> items = StringHelper.clean(subqueries); items = StringHelper.wrap(items, "(", ")"); return StringHelper.join(items, " AND "); }