Download - POO1501 - Composición java
![Page 1: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/1.jpg)
A r r e g l o s [ ] J a v a
Jose Bovet Derpich!
8 /1 4
POO2201
![Page 2: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/2.jpg)
Unidad de Aprendizaje N°1 Arreglos y colaboración de clases
![Page 3: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/3.jpg)
Aprendizajes Esperados • Construye clases que cuenten con atributos del tipo arreglos que
contienen tipos de datos primitivos para resolver un problema !• Construye clases que cuenten con atributos del tipo arreglos que
contienen referencias para resolver un problema !• Construye clases ubicadas en package distintos para resolver un
problema !• Construye clases de acuerdo a los estándares de la industria !
![Page 4: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/4.jpg)
•Describir arreglos •Definir sintaxis del arreglo •Emplear el recorrido en un arreglo •Aplicar arreglos •Describir packages
OBJETIVOS
![Page 5: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/5.jpg)
oK… pero que es un
Arreglo[?]
![Page 6: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/6.jpg)
Usemos la Imaginación…
![Page 7: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/7.jpg)
![Page 8: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/8.jpg)
![Page 9: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/9.jpg)
Cuantos libros se pueden almacenar??
![Page 10: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/10.jpg)
Cuantos libros se pueden almacenar??
![Page 11: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/11.jpg)
Cuantos libros se pueden almacenar??
Como puedo obtener este libro?
![Page 12: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/12.jpg)
Cuantos libros se pueden almacenar??
Como puedo obtener este libro?
![Page 13: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/13.jpg)
Cuantos libros se pueden almacenar??
Como puedo obtener este libro?
y si coloco un libro mas aqui…
![Page 14: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/14.jpg)
Cuantos libros se pueden almacenar??
Como puedo obtener este libro?
y si coloco un libro mas aqui…
![Page 15: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/15.jpg)
>> Un arreglo es un conjunto de valores de un mismo tipo y almacenados secuencialmente.
![Page 16: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/16.jpg)
Se referencia mediante una variable y un índice numérico en corchetes para acceder a cada elemento del arreglo.
Los índices son números enteros consecutivos empezando por el 0.
![Page 17: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/17.jpg)
“ Como declarar un arreglo[…] ”
![Page 18: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/18.jpg)
Text
Declaración:
•Nombre del Arreglo •Tipos de datos que almacenara.
![Page 19: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/19.jpg)
Ejemplos !
Forma estándar Forma alternativa…
![Page 20: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/20.jpg)
CREAR un arreglo[?]
![Page 21: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/21.jpg)
Crear un arreglo significa reservar espacio en memoria para sus elementos y asignarle un nombre:
![Page 22: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/22.jpg)
nombre = new tipo[tamaño];
Sintaxis:
![Page 23: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/23.jpg)
nombre = new tipo[tamaño];
!
• nombre: el identificador del arreglo. • tipo: tipo de elementos del arreglo. • tamaño: número de elementos
Sintaxis:
![Page 24: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/24.jpg)
Ejemplo !
Tipo Objeto
} Primitivos
declaración inicialización
![Page 25: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/25.jpg)
Se puede declarar y crear el arreglo al mismo tiempo:
6.0 6.3 6.5
0 1 2
Largo: 3
![Page 26: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/26.jpg)
mportante…
![Page 27: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/27.jpg)
>> Los arreglos en java son Dinámicos, pero no extensibles. !
>>Deben ser creados con el tamaño hasta el fin de vida de este. !
>> Los índices de los arreglos en Java comienzan en 0 y terminan en N-1, para un arreglo de tamaño N.
!
>> El largo de un arreglo se puede conocer de la siguiente manera: nombreArreglo.length
![Page 28: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/28.jpg)
>> Crear un array e inicializarlo con valores
![Page 29: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/29.jpg)
Ejemplos!
![Page 30: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/30.jpg)
Como accedo a los elementos del
arreglo???
![Page 31: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/31.jpg)
>> Se utiliza el nombre del arreglo seguido por el índice entre corchetes.
!
>> El indice nos indica la posición del elemento.
![Page 32: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/32.jpg)
![Page 33: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/33.jpg)
Pedro
JuanDiego
Andres tom
>> Obtener a Diego… >> Ordenarlos por nombre…
>> Invertir el orden >> quitar a Tom…
!
![Page 34: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/34.jpg)
![Page 35: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/35.jpg)
Colecciones en Java
Collections
![Page 36: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/36.jpg)
![Page 37: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/37.jpg)
Que son?
![Page 38: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/38.jpg)
Las colecciones son objetos que contienen objetos . se usan para:
!
• almacenar • obtener • manipular • y comunicar datos.
!
Colecciones:
![Page 39: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/39.jpg)
Los objetos incluídos en ellas suelen ser del mismo tipo, aunque no necesariamente, depende de si son o no
genéricas.
![Page 40: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/40.jpg)
Las colecciones se diferencian de los arrays en que su tamaño no es fijo, esto es, son dinámicas. Se pueden
realizar operaciones de incluir, eliminar, obtener, encontrar o recorrer una colección.
![Page 41: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/41.jpg)
“ Como declarar un coleccion < > ”
![Page 42: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/42.jpg)
List<tipo> nombreArray = new ArrayList<tipo>();
Sintaxis:
![Page 43: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/43.jpg)
List<tipo> nombreArray = new ArrayList<tipo>();!
• List: Interfaz Extiende de Collection • nombreArray: el identificador del arreglo • tipo: tipo de elementos del arreglo.(Objeto) • ArrayList: Implementacion de de List
Sintaxis:
![Page 44: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/44.jpg)
No se pueden usar tipos primitivos. Para un tipo primitivo se debe utilizar su clase envolvente
Consideradiones:
ArrayList<Integer> numeros = new ArrayList<Integer>()
![Page 45: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/45.jpg)
Algunos métodos….
![Page 46: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/46.jpg)
“ Como recorrer una coleccion”
![Page 47: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/47.jpg)
![Page 48: POO1501 - Composición java](https://reader031.vdocuments.pub/reader031/viewer/2022032715/55ae5ab41a28abe47d8b458b/html5/thumbnails/48.jpg)
Agenda Telefonica..