我有不同类型的名字。喜欢
ABC BCD, EFG HGF, HGF HJK
我想,
用"and"
. 所以,格式会是这样的
ABC BCD, EFG HGF & HGF HJK
我试过这个
names = "Jon Benda, Jon Wetchler, Thomas Leibig "
StringBuilder sbd = new StringBuilder();
String[] n = getNames.split("\\s+");
System.out.println(n.length);
for (int i = 0; i < n.length; i++) {
sbd.append(n[i]);
System.out.print(n[i]);
if (i < n.length - 3)
sbd.append(" ");
else if (i < n.length - 2)
sbd.append(" & ");
}
System.out.print("\n");
System.out.print(sbd);