How to convert ArrayList to HashSet for eliminating duplicates

 

List<String> al = new ArrayList<>();
// add elements to al, including duplicates
Set<String> hs = new HashSet<>();
hs.addAll(al);
al.clear();
al.addAll(hs);

http://stackoverflow.com/questions/203984/how-do-i-remove-repeated-elements-from-arraylist

Advertisements

মন্তব্য করুন

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  পরিবর্তন )

Google+ photo

You are commenting using your Google+ account. Log Out /  পরিবর্তন )

Twitter picture

You are commenting using your Twitter account. Log Out /  পরিবর্তন )

Facebook photo

You are commenting using your Facebook account. Log Out /  পরিবর্তন )

Connecting to %s