Concatenating elements in an array to a string

前端 未结 19 2278
慢半拍i
慢半拍i 2020-12-08 02:43

I\'m confused a bit. I couldn\'t find the answer anywhere ;(

I\'ve got an String array:

String[] arr = [\"1\", \"2\", \"3\"];

then

19条回答
  •  执笔经年
    2020-12-08 03:04

    I have just written the following:

    public static String toDelimitedString(int[] ids, String delimiter)
    {
        StringBuffer strb = new StringBuffer();
        for (int id : ids)
        {
          strb.append(String.valueOf(id) + delimiter);
        }
        return strb.substring(0, strb.length() - delimiter.length());
     }
    

提交回复
热议问题