Initialized to the value 0 boolean arrays are

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lare the array: int theArray; // this is the “standard” int theArray; int theArray; int theArray ; •  This is not an allowed declaration in Java: int[5] theArray; CPSC 324 ‐‐ Spring 2010 12 6 1/19/10 Initializing Java Arrays •  You can use a constant (like we did before) int theArray = {100, 10, 1000, 20, 200}; •  Or you can explicitly allocate memory: int theArray = new int[5]; •  This creates an array of 5 elements, each initialized to the value 0 –  Boolean arrays are initialized to false –  Arrays of object types are initialized to null (more later) CPSC 324 ‐‐ Spring 2010 13 Initializing Java Arrays •  Once you declare an array int theArray = {100, 10, 1000, 20, 200}; – or – int theArray = new int[5]; •  You cannot initialize it again with a const theArray = {1, 2, 3, 4, 5}; // compile error! •  You can assign it a new array theArray...
View Full Document

This document was uploaded on 03/18/2014 for the course CPSC 324 at Gonzaga.

Ask a homework question - tutors are online