JAVA SET MAP
Résolu
alexandre23
Messages postés
36
Date d'inscription
Statut
Membre
Dernière intervention
-
alexandre23 Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
alexandre23 Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Voila je voulais savoir si quelqu'un connaissait la syntaxe afin de remplir un Set et une Map directement lors de son instanciation (si c'est possible). Donc sans passer dans une méthode de remplissage.
Set<Integer> setAge = new HashSet<Integer>(); ????
Genre : Set<Integer> setAge = new HashSet<Integer>(3){1,2,3};
ET
Map<String, Integer> mapNomAge = new HashMap<String, Integer>(); ????
Genre : Map<String, Integer> mapNomAge = new HashMap<String, Integer>(2){("hello",2),("salut"),10};
Merci d'avance
Salutation
Alex
Voila je voulais savoir si quelqu'un connaissait la syntaxe afin de remplir un Set et une Map directement lors de son instanciation (si c'est possible). Donc sans passer dans une méthode de remplissage.
Set<Integer> setAge = new HashSet<Integer>(); ????
Genre : Set<Integer> setAge = new HashSet<Integer>(3){1,2,3};
ET
Map<String, Integer> mapNomAge = new HashMap<String, Integer>(); ????
Genre : Map<String, Integer> mapNomAge = new HashMap<String, Integer>(2){("hello",2),("salut"),10};
Merci d'avance
Salutation
Alex
A voir également:
- Setmap java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
2 réponses
ok merci,
Mais la par exemple pour le hashset, il y a un constructeur comme ceci :
HashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.
Mais alors la niveau syntaxe je ne comprend plus rien et il n y a pas d'exemple
Avez vous deja eu a faire a ca ?
Mais la par exemple pour le hashset, il y a un constructeur comme ceci :
HashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.
Mais alors la niveau syntaxe je ne comprend plus rien et il n y a pas d'exemple
Avez vous deja eu a faire a ca ?
En fait ça veut dire que tu peux faire :
ArrayList<String> liste = new ArrayList<String>(); liste.add("a"); liste.add("b"); ... HashSet<String> set = new HashSet<String>(liste); HashMap<String,Integer> map1 = new HashMap<String,Integer>(); map1.put("a",1); map1.put("b",2); ... HashMap<String,Integer> map2 = new HashMap<String,Integer>(map1);