Java: Création, modification et affichage d’un HashSet

Author:

 int,string,char,static, url, socket, url, socket, java
Download

 
import java.util.*;
/*
 *  Création, modification et affichage d'un HashSet
 *
 **/
public class ExempleHashSet 
{
 
   public static void main (String[] args) 
   {
   	// Créer une HashSet avec une capacité initiale
   	Set<Integer> s1 = new HashSet<Integer>(8);
   	 int hash = 0;
   	 String str="abnghtpo";
     for (char ch : str.toCharArray()) 
       {
          hash = hash * 31 + ch;
          s1.add(hash);
        }
 
      // Afficher le contenu de HashSet
      Iterator iter=s1.iterator();
      while(iter.hasNext())
      {
      	System.out.println (iter.next());
      }
 
   }
 
}

Cet article Java: Création, modification et affichage d’un HashSet est apparu en premier sur .