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

前端 未结 5 1194
谎友^
谎友^ 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:45

    Can you try this using for loop like this:

    EDITED :

    private String[] mostlyMatchedKeywordsStrings;
        private List cloudChipList = new ArrayList<>();
    
        mostlyMatchedKeywordsStrings = serialResponse.getData().getGenres();
    
        for (String str : mostlyMatchedKeywordsStrings) {
            cloudChipList.add(str);
        }
        if (cloudChipList.size() > 0) {
            for (int i = 0; i < cloudChipList.size(); i++) {
    
                if (i == (cloudChipList.size() - 1)) //true only for last element
                    infoSerialFrag_GenreChips.add(cloudChipList.get(i));
    
                else
                    infoSerialFrag_GenreChips.add(cloudChipList.get(i) + ","); //this will execute for 1st to 2nd last element
            }
        }
    

提交回复
热议问题