Aê pessoal,
eu curioso com os estudos sobre a perfomance da classes que implementam Collection fiz um pequeno teste , e queria ver se entendi certo... ou se fiz besteira no codigo pra tentar entender ....uhauauauha
mas eh isso....
Pelo q estudei ... o LinkedList é melhor quando voce quer inserir muitos elementos no meio da Colecao ... mas naum eh o q parece ... quer dizer
... acho q tentei fazer da maneira q entendi ...
se alguem tem alguma explicacao ... pode postar pra gente vê na simulacao se a teoria eh mesmo compativel com a pratica!!!
public static void main(String[] args) {
ArrayList c1 = new ArrayList();
LinkedList c2 = new LinkedList();
for (int i=0; i<1000; i++){
c1.add(new Integer(i));
c2.add(new Integer(i));
}
double l1 = System.currentTimeMillis();
int pos = 0;
for(int i=0;i<10000;i++){
pos = (int)( (c1.size()/2) - 10);
c1.add( pos, new Integer(i)) ;
}
double l2 = System.currentTimeMillis() - l1;
double tempo = l2/1000;
System.out.println("tempo do ArrayList: " + tempo + " s");
l1 = System.currentTimeMillis();
pos = 0;
for(int i=0;i<10000;i++){
pos = (int)( (c2.size()/2) - 10);
c2.add( pos, new Integer(i)) ;
}
l2 = System.currentTimeMillis() - l1;
tempo = l2/1000;
System.out.println("tempo do LinkedList: " + tempo + " s");
}