Java - Append quotes to strings in an array and join strings in an array

前端 未结 7 752
后悔当初
后悔当初 2020-12-13 00:04

I would like to append double quotes to strings in an array and then later join them as a single string (retaining the quotes). Is there any String library which does this?

7条回答
  •  余生分开走
    2020-12-13 00:24

    public static void main(String[] args) {
        // TODO code application logic here
        String [] listOfStrings = {"day", "campaign", "imps", "conversions"};
        String output = "";
    
        for (int i = 0; i < listOfStrings.length; i++) {
            output += "\"" + listOfStrings[i] + "\"";
            if (i != listOfStrings.length - 1) {
                output += ", ";
            }
        }
    
        System.out.println(output);
    }
    

    Output: "day", "campaign", "imps", "conversions"

提交回复
热议问题