Creating Arrays
Creating Arrays
Method 1: The new Keyword
// Shopping list with 5 elements (slots)
String[] shoppingList = new String[5];
// Ages of 8 people (slots for 8 ages)
int[] ages = new int[8];
// List of 3 random numbers (slots for them)
float[] randNums = new float[3];Method 2: Using Brackets and Initial Values
Last updated