import java.util.HashSet;Sortie:
public class ToArray{
public static void main(String[] args) {
// Créer une HashSet
HashSeths = new HashSet ();
//remplir les éléments
hs.add("E1");
hs.add("E2");
hs.add("E3");
hs.add("E4");
hs.add("E5");
// affichage
System.out.println("HashSet : "+ hs);
// créer un tableau
String[] tableau = new String[hs.size()];
hs.toArray(tableau);
// affichage du tableau
System.out.print("tableau : ");
for(String e : tableau){
System.out.print(e+" ");
}
}
}
HashSet : [E2, E1, E4, E3, E5]
tableau : E2 E1 E4 E3 E5
Please disable your ad blocker and refresh the window to use this website.