Arrays

Páginas: 5 (1088 palabras) Publicado: 17 de abril de 2011
Page 1 Página 1 |
Java Arrays Java Arrays
Lawrence M. Brown Lawrence M. Brown
ktee@erols.com ktee@erols.com
© 1998 © 1998
December 31, 1998 31 de diciembre 1998
1 1
Java Arrays Java Arrays
1. 1.
Introduction Introducción
In Java arrays are objects that represent a group of contiguous memory locations of the En Java los arrays son objetos que representan un grupo de posicionesde memoria contiguas de la
same type and referred to by the same name. mismo tipo y que hace referencia el mismo nombre. The element type for an array can be any primitive El tipo de elemento de una matriz puede ser cualquier primitiva
data type or object. tipo de datos u objeto.
2. 2.
Declaring and Allocating Arrays Declaración y asignación de matrices
Arrays can be created using thenew operator or by declaring a static initializer. Las matrices se pueden crear utilizando el nuevo operador o declarando un inicializador estático. The new El nuevo
operator specifies the size of the array. operador especifica el tamaño de la matriz.
int[] c, d; int [] c, d;
// declare references to array c and d / / Declarar referencias a la serie c, d
c = new int [ 4 ]; c = new int [4];// allocate memory for the 4 elements in array c / / Asignar memoria para los 4 elementos en orden de c
d = new int [ 125 ]; d = new int [125];
// allocate memory for the 125 elements in array d / / Asignar memoria para los 125 elementos de la matriz d
byte[] b = new byte [ 100 ]; byte b] [= new byte [100];
// declare and allocate memory for array b / / Declarar y asignar memoria para lamatriz b
• •
An array intializer may be any arbitrary expression. Un intializer matriz puede ser cualquier expresión arbitraria.
int c = 15; int c = 15;
int[] primes = { 1, 2, 3, 5, 7, 9, 11 }; int [] primos = {1, 2, 3, 5, 7, 9, 11};
int[] a = { 1, primes[2], c, (int)Math.pow(2,2) }; Int [] a = {1, primos [2], c, (int) Math.pow (2,2)};
• The first element in every array is the zerothelement. • El primer elemento de cada conjunto es el elemento cero.
• When memory is allocated for an array, the elements are automatically initialized to their • Cuando se asigna memoria para una matriz, los elementos se inicializan automáticamente a su
default values: zero for all numeric primitive data types, false for boolean variables and null for valores por defecto: cero para todos lostipos primitivos de datos numéricos, false para variables booleanas y null para
references. referencias.
• •
As with all objects, if the array reference (object reference) is assigned a null value, then the Al igual que con todos los objetos, si la referencia al array (referencia de objeto) se le asigna un valor nulo, entonces el
garbage collector will reclaim the dereferenced (unused)memory. recolector de basura será recuperar el desreferenciado (sin usar) de memoria.

Page 2 Página 2 |
Java Arrays Java Arrays
Lawrence M. Brown Lawrence M. Brown
ktee@erols.com ktee@erols.com
© 1998 © 1998
December 31, 1998 31 de diciembre 1998
2 2
3. 3.
Accessing Array Elements Acceso a los elementos de matriz
Placing an integer-valued expression inside square brackets canaccess an array Colocación de una expresión con valores enteros entre corchetes puede tener acceso a una matriz
element, where the brackets are proceeded by the name of the array. elemento, donde los soportes se procedió con el nombre de la matriz.
Accessing Array Elements Example Acceso a los elementos de matriz Ejemplo
int c = 15, j = 1; int c = 15, j = 1;
int[] primes = { 1, 2, 3, 5, 7,9, 11 }; int [] primos = {1, 2, 3, 5, 7, 9, 11};
int[] a = { 1, primes[2], c, (int)Math.pow(2,2) }; Int [] a = {1, primos [2], c, (int) Math.pow (2,2)};
System.out.println( "\n Before: \na[0] is " + a[0] ); System.out.println ("\ n Antes: \ na [0] es" + a [0]);
System.out.println( "a[1] is " + a[1] \n "a[2] is " + a[2] ); System.out.println ("a [1] es" + a [1] \ n ", un [2] es" + a [2]);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Arrays
  • Arrays
  • Arrays
  • Arrays
  • Arrays
  • Los Arrays
  • Arrays
  • Arrays

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS