Creating and Using Arrays in Java

Chapter 4 - Creating and Using Arrays

    Creating and Using Arrays in Java

  • Creating and Using Arrays

              An array is used to store a collection of data, but it is used array as a collection of variables of the same type.

              Instead of declaring individual variables, such as number0, number1, ..., and number99, declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables.

    Declaring Array Variables:

              To declare a variable to reference the array, specify the type of array the variable can reference. 

    Syntax:
    dataType[] arrayRefVar;   // preferred way.
    

    or

    dataType arrayRefVar[];  //  works but not preferred way.
    br />
    dataType[] arrayRefVar is preferred.

    Example:

    double[] myList;         // preferred way.
    

    or

    double myList[];         //  works but not preferred way.
    

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy