Split a large string into SET elements

Possible duplicate:
Java - easily convert an array to settings

Can someone help me with a version of the following expression that I can use for SET instead of ArrayList?

ArrayList<String> items = new ArrayList<String>(Arrays.asList(comment.split(", ")));

PS: Comment is a large string of words separated by ",". You need to make a separate element of the word, dividing them into sections with a comma.

+5
source share
1 answer

You use the same approach by simply passing the converted array to the Set constructor :

Set<String> items = new HashSet<String>(Arrays.asList(comment.split(", ")));

Further simplification is impossible without third-party libraries, but there are no drawbacks, since Arrays.asListO (1) is executed in constant time.

+7
source

All Articles