12.07.2015 Views

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

155 COLLECTIONSOperação ArrayList LinkedListAdicionar ou Remover do final da lista ☺ ☺Adicionar ou Remover do começo da ☹ ☺listaAcessar elementos pela posição ☺ ☹Os métodos da classe Vector possui <strong>de</strong>sempenho um pouco pior do que os da classe ArrayList.Porém, a classe Vector implementa lógica <strong>de</strong> sincronização <strong>de</strong> threads.Exercícios <strong>de</strong> Fixação1 Crie um projeto no eclipse chamado Collections.2 Vamos calcular o tempo das operações principais das listas.1 import java . util . ArrayList ;2 import java . util . LinkedList ;3 import java . util . List ;45 public class TestaAdicionaNoFinal {6 public static void main ( String [] args ) {7 ArrayList arrayList = new ArrayList ();8 LinkedList linkedList = new LinkedList ();910 long tempo = TestaAdicionaNoFinal . adicionaNoFinal ( arrayList );11 System . out . println (" ArrayList : " + tempo + "ms");1213 tempo = TestaAdicionaNoFinal . adicionaNoFinal ( linkedList );14 System . out . println (" LinkedList : " + tempo + "ms");1516 }1718 public static long adicionaNoFinal ( List lista ) {19 long inicio = System . currentTimeMillis ();2021 int size = 100000;2223 for ( int i = 0; i < size ; i ++) {24 lista . add (i);25 }2627 long fim = System . currentTimeMillis ();2829 return fim - inicio ;30 }31 }Código Java 18.16: TestaAdicionaNoFinal.java1 import java . util . ArrayList ;2 import java . util . LinkedList ;3 import java . util . List ;45 public class TestaAdicionaNoComeco {6 public static void main ( String [] args ) {7 ArrayList arrayList = new ArrayList ();8 LinkedList linkedList = new LinkedList ();910 long tempo = TestaAdicionaNoComeco . adicionaNoComeco ( arrayList );11 System . out . println (" ArrayList : " + tempo + "ms");12www.<strong>k19</strong>.com.br 155

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!