Problème de taille d'ArrayList
Bonjour,
Je travaille sur l’implémentation Java du Type abstrait Polynôme, il s'appuis sur le type abstrait Monôme déjà implémenter et cela dans le cadre de mes études.
Le type Polynôme doit être une arraylist j'ai donc chercher comment l'utiliser ici : http://javasearch.developpez.com/j2s...ArrayList.html
Mais j'ai quelque problème:
Quand je définie une taille ou essaye de l’agrandir l’opération n'effectue aucun changement:
Si je fait:
Code:
1 2 3
| ArrayList<Monôme> Poly = new ArrayList<Monôme>(10);
Poly.ensureCapacity(100);
Poly.add(2,new Monôme(4,2)); |
J'obtient:
Code:
1 2 3 4
| Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:612)
at java.util.ArrayList.add(ArrayList.java:426)
at test.run.main(run.java:9) |
Le but est de ranger les monôme dans la case de leur exposant -1, 8^3 serait au rang 2 cela pour ensuite faciliter les opération somme et multiplication de Polynôme.
j'ai fais des test de taille et avec sa:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| package test;
import java.util.*;
public class run {
public static void main(String[] args)
{
ArrayList<Monôme> Poly = new ArrayList<Monôme>(10);
Poly.ensureCapacity(999999);
System.out.println(Poly.size());
Poly.add(new Monôme(4,2));
Poly.add(new Monôme(5,3));
System.out.println(Poly.size());
System.out.println(Poly);
}
} |
il me retourne:
Pourquoi il garde une taille de 0?