Exemple de la boucle ‘forin’ avec une Collection générique

Author:


{filelink=4414}


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ForInGenericsDemo {

  public static void main(String[] args) {

    List listMot = new ArrayList();
    Set wordset = new HashSet();

    System.out.println("Assigner les argument � la liste dynamique");
    for(String word : args) {
      System.out.print(word + " ");
      listMot.add(word);
      wordset.add(word);
    }

    System.out.println();

    System.out.println("Afficher les mots de la list 'listMot' ");
    for(String word : listMot) {
      System.out.print(word + " ");
    }

    System.out.println();

    System.out.println("Afficher les mots de la list 'wordset'");
    for(String word : wordset) {
      System.out.print(word + " ");
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *