Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CSV to Set<String> in Java

Tags:

java

tokenize

I have a comma-seperated value string in Java:

String s = "a,b,c,d";

I need to tokenize it (with comma as the delimiter) and turn it into a Set<String>. Is StringTokenizer my best bet or is there a more efficient way?

like image 338
IAmYourFaja Avatar asked Dec 12 '22 00:12

IAmYourFaja


1 Answers

If you try to solve generally CSV parsing to set be aware that there are quotes and coma escaping to handle. This is why libraries like OpenCSV exist. Otherwise you just need to do as hvgotcodes described.

like image 133
jolivier Avatar answered Dec 30 '22 22:12

jolivier