La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

FUNDAMENTALS OF THE JAVA PROGRAMMING LANGUAGE

Presentaciones similares


Presentación del tema: "FUNDAMENTALS OF THE JAVA PROGRAMMING LANGUAGE"— Transcripción de la presentación:

1 FUNDAMENTALS OF THE JAVA PROGRAMMING LANGUAGE
(SL-110) CAPÍTULO 11: CREACIÓN Y USO DE ARREGLOS Ing. Ronald Criollo

2 AGENDA Arreglos. Declaración de Arreglos. Inicialización de Arreglos.
Uso de Arreglos. Arreglos Multidimensionales.

3 ARREGLOS Es una colección de OBJETOS o variables PRIMITIVAS.
Es útil cuando el numero de variables de referencia es muy grande.

4 ARREGLOS Todos los miembros de un arreglo son del mismo tipo y tamaño.
El acceso a los miembros es rápido y eficiente.

5 ARREGLOS

6 ARREGLOS

7 DECLARACIÓN Sintaxis Ejemplo type [] array_identifier;
char [] status; int [] ages; Shirt [] shirts; String [] names;

8 INSTANCIACION Sintaxis Ejemplo array_identifier = new type [length];
status = new char [20]; ages = new int [5]; names = new String [7]; shirts = new Shirt [3];

9 INICIALIZACION Sintaxis Ejemplo array_identifier[index] = value;
ages[0] = 19; ages[1] = 42; ages[2] = 92; ages[3] = 33; ages[4] = 46; shirts[0] = new Shirt();

10 INSTANCIACION

11 INDICE Para el acceso a los MIEMBROS de un ARREGLO es usado un INDICE.
Indice es un tipo de dato int. Para acceder al primer miembro es 0. status[0] = ’3’; names[1] = "Fred Smith"; ages[1] = 19; prices[2] = 9.99F;

12 DECLARACION, INSTANCIACION E INICIALIZACION DE UN ARREGLO UNIDIMENSIONAL
Sintaxis type [] array_identifier = {comma-separated list of values or expressions}; Ejemplo

13 INICIALIZACION DE ARREGLO DE OBJETOS
La inicialización de arreglos de objetos requiere que los objetos esten instanciados primero. Account[] accountList; accountList = new Account[2]; accountList[0] = new Account(203.50); accountList[1] = new Account( );

14 INICIALIZACION DE ARREGLO DE OBJETOS

15 ACCESANDO A ELEMENTOS DE UN ARREGLO
El tipo de dato del Indice debe ser int. El valor del Indice puede ser resultado de un calculo. loopValue = arrayOfInts[index – 1]; System.arraycopy() puede ser usado para copiar el contenido de un arreglo a otro System.arraycopy(arrayOfInts, 0, anotherArrayOfInts, 0, arrayOfInts.length); Account[] accountList; accountList = new Account[2]; accountList[0] = new Account(203.50); accountList[1] = new Account( );

16 RECORRIENDO UN ARREGLO UNIDIMENSIONAL
int [] myArray; myArray = new int[100]; for (int count = 0; count < myArray.length; count++) { myArray[count] = count; } Account[] accountList; accountList = new Account[2]; accountList[0] = new Account(203.50); accountList[1] = new Account( );

17 Los miembros de un arreglo pueden ser buscados y ordenados.
USO DE ARREGLOS Un arreglo puede ser una forma de pasar un largo numero de argumentos a un metodo. Arreglos paralelos pueden ser usados para almacenar informacion relacionada. Los miembros de un arreglo pueden ser buscados y ordenados.

18 ARREGLOS MULTIDIMENSIONALES
Los arreglos multidimensionales pueden ser usados en vez de los arreglos paralelos. Son declarados con multiples pares de []. int[][] multiArray = new int[20][30]; Usa un Indice independiente para cada dimension. loopValue = multiArray[3][6];

19 ARREGLOS MULTIDIMENSIONALES

20 RECORRIENDO UN ARREGLO MULTIDIMENSIONAL
Lazos FOR anidados pueden ser usador para recorrer los elementos de un arreglo multidimensional. public int[][] myArray = new int[4][5]; for(x = 0; x < 4; x++) { for(y = 0; y < 5; y++) { myArray[x][y] = x * y; }


Descargar ppt "FUNDAMENTALS OF THE JAVA PROGRAMMING LANGUAGE"

Presentaciones similares


Anuncios Google