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

前端 未结 5 1198
谎友^
谎友^ 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 18:05

    Do it the old Java 6 way and add the comma yourself unless its the last element in the list.

    See the following example:

    private String[] mostlyMatchedKeywordsStrings = serialResponse.getData().getGenres();
    private List cloudChipList = new ArrayList<>();
    
    for (int i = 0; i < mostlyMatchedKeywordsStrings.length; i++) {
    
        String str = mostlyMatchedKeywordsStrings[i];
    
        if (i + 1 < mostlyMatchedKeywordsStrings.length) str = str + ", ";
    
        cloudChipList.add(str);
    
        if (cloudChipList.size() > 0) {
           infoSerialFrag_GenreChips.addChip(str);
        }
    }
    

提交回复
热议问题