public String concatenateFields(String field1, String field2, String field3) { StringBuilder sb = new StringBuilder(); boolean separatorAdded = false; if (field1 != null && !field1.isEmpty()) { sb.append(field1); separatorAdded = true; } if (field2 != null && !field2.isEmpty()) { if (separatorAdded) { sb.append('-'); } sb.append(field2); separatorAdded = true; } if (field3 != null && !field3.isEmpty()) { if (separatorAdded) { sb.append('-'); } sb.append(field3); } return sb.toString(); }
标签:String,三个,field2,field3,拼接,为空,sb,append,separatorAdded From: https://www.cnblogs.com/qxqbk/p/18197193