Adding comma separated strings to an ArrayList and vice versa

前端 未结 11 1252
旧巷少年郎
旧巷少年郎 2021-01-01 05:18

How to add a comma separated string to an ArrayList? My string \"returnedItems\" could hold 1 or 20 items which I\'d like to add to my ArrayList \"selItemArrayList\".

<
11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 05:47

    If the strings themselves can have commas in them, things get more complicated. Rather than rolling your own, consider using one of the many open-source CSV parsers. While they are designed to read in files, at least OpenCSV will also parse an individual string you hand it.

    • Commons CSV
    • OpenCSV
    • Super CSV
    • OsterMiller CSV

提交回复
热议问题