10.05.2014 Views

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

164 Programación I<br />

}<br />

}<br />

3)<br />

Se presentan algunos de los métodos disponibles. En algunos casos, hay otras posibilidades.<br />

a) array, b) ArrayList, c) HashMap<br />

Permite contener<br />

array: Elementos de la misma clase<br />

ArrayList: Colección arbitraria de objetos<br />

HashMap: Estructura de datos en la cual un elemento (clave) es usado para ubicar<br />

un segundo elemento (valor)<br />

Creación:<br />

Camion arrayCamion[];<br />

arrayCamion = new Camion[3];<br />

ArrayList miLista;<br />

miLista = new ArrayList();<br />

HashMap hashCamion;<br />

hashCamion = new HashMap ();<br />

Para averiguar el tamaño:<br />

a) arrayCamion.length; (no es método) tamaño fijo<br />

b) arrayListCamion.size(); tamaño dinámico<br />

c) hashCamion.size(); tamaño dinámico<br />

Para saber si está un cierto objeto:<br />

a) NO<br />

b) arrayListCamion.contains(XX);<br />

c) hashCamion.containsValue(XX); (si es valor)<br />

hashCamion.containsKey(XX); (si es clave)<br />

Para ubicar el elemento de posición j:<br />

a) arrayCamion[j]<br />

b) arrayListCamion.get(j);<br />

c) NO<br />

Para agregar elemento XX<br />

a) arrayCamion[...] = XX<br />

b) arrayListCamion.add(XX);<br />

c) hashCamion.put(clave, valor); indicar clave y valor<br />

Para eliminar elemento XX<br />

a) NO<br />

b) arrayListCamion.remove(XX);<br />

c) hashCamion.remove(XX); (XX debe ser clave)<br />

Para ordenar:<br />

a) algoritmos de ordenación<br />

b) Collections.sort();<br />

c) usar estructura auxiliar

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

Saved successfully!

Ooh no, something went wrong!