Single Dimensional Arrays Flashcards
Is a data structure that represents a collection of same types data elements
Array
How much can a single dimensional array store data elements?
One row
Strings are Arrays
String Name = “John Smith”;
String courseNumber;
courseNumber = new String (“CS 1301’’);
How do you allocate memory space for the array? arrayRefVar= new datatype [arraySize];
Example:
myList = new double [10];
yourList = new int [100];
herList
How do you declare a single-dimensional array in Java?
Us the syntax: datatype[] array RefVar;
Example: int[] myList;
How do you create an array in Java?
Use the syntax: arrayRefVar= new datatype[arraySize];
Example: myList = new int[10];
How do you access elements in an array?
Access elements using the array’s index, starting at 0.
Example: mylist [0] = new int[10]
How do you create an array in Java?
Use the syntax: arrayRefVar = new datatype [arraySize];
Example: myList = new int(10);
How do you access elements in an array?
Access elements using the array’s index, starting at 0.
Example: myList[0] = 25.7;
What are the default values for an array in Java?
Numeric types: 0, Boolean: False, Object references: null
Indexed variables in an array?
An indexed variable references to array elements using their using their index, like arrayRefVar[index];