Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; import java.util.Collections; import java.util.HashSet; import java.util.Set; public class Main { public static final String COMMA = ","; /** * string convert to set */ public static Set<String> stringConvertToSet(String values, String separate) { if (values == null) { return null; } if (values.isEmpty()) { return Collections.EMPTY_SET; } String sp = TextUtils.isEmpty(separate) ? COMMA : separate; String[] sV = values.split(sp); Set<String> set = new HashSet<>(); for (String v : sV) { set.add(v); } return set; } }