Tutorialspoint

Convert an ArrayList to HashSet in Java

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
public class Main {
   public static void main(String[] args) {
		List<String> l = new ArrayList<String>();
		l.add("Accent");
		l.add("Speech");
		l.add("Diction");
		l.add("Tone");
		l.add("Pronunciation");
		Set<String> s = new HashSet<String>(l);
		System.out.println("HashSet elements...");
		for (Object ob : s)
		   System.out.println(ob);
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.