Convert int[] to comma-separated string

后端 未结 6 784
情深已故
情深已故 2021-01-12 23:45

How can I convert int[] to comma-separated String in Java?

int[] intArray = {234, 808, 342};

Result I want:

\"         


        
6条回答
  •  一个人的身影
    2021-01-13 00:22

            int[] intArray = {234, 808, 342, 564};
            String s = Arrays.toString(intArray);
            s = s.substring(1,s.length()-1);
    

    This should work. basic idea is to get sub string from Arrays.toString() excluding first and last character

    If want quotation in result, replace last line with:

    s = "\"" + s.substring(1,s.length()-1) + "\"";
    

提交回复
热议问题