如果不为空或为空,请加入逗号

如果不为空或为空,请加入逗号,第1张

如果不为空或为空,请加入逗号
public class So20111214a {    public static String join(String[] argStrings) {        if (argStrings == null) { return "";        }        String ret = "";        if (argStrings.length > 0) { ret = argStrings[0];        } // if        for (int i = 1; i<argStrings.length; i++) { ret += (argStrings[i] == null)          ? ""          : (argStrings[i].isEmpty()   ? ""   :  ( "," + argStrings[i] ) );        } // for        return ret;    } // join() method    public static void main(String[] args) {        String[] grandmasters = {   "Emanuel Lasker",  "José Raúl Capablanca",  "Alexander Alekhine",  "Siegbert Tarrasch",  "Frank Marshall"          };        String[] s1 = null;        String[] s2 = {};        String[] s3 = { "Mikhail Botvinnik" };        System.out.println(join(s1));        System.out.println(join(s2));        System.out.println(join(s3));        System.out.println(join(grandmasters));        System.out.println(join(new String[]{"I", "love", "", null, "u!"}));    } // main() method    } // So20111214a class

PS:很抱歉使用??接线员-我必须快点做,我在工作。:)



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5499799.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存