How to add a comma at the end of every element in ArrayList On Android

前端 未结 5 1229
谎友^
谎友^ 2021-01-25 17:08

In my application I want use this Library for show ArrayList items.
My ArrayList from server:

\"genres\": [
      \"Action\",
         


        
5条回答
  •  离开以前
    2021-01-25 17:59

    Although it is late, just case if someone else comes to this thread... If you are using Java 8, you can use streaming and Collectors interfaces like the following:

    List cloudChipList = new ArrayList();
        cloudChipList.add("Action");
        cloudChipList.add("Comedy");
        cloudChipList.add("Family");
    
        String result = cloudChipList.stream().collect(Collectors.joining(" , ", "Genre: ", "\n"));
        System.out.println(result);
    

    Here Collectors.joining adds delimiter, prefix and suffix to the result, but it has an option with only the delimter, too.

提交回复
热议问题