Java Examples – Arrays in Java Example




  • An array is an ordered list of values
  • An array of size N is indexed from zero to N-1
  • A particular value in an array is referenced using the array name followed by the index in brackets
  • For example, the expression
  • That expression represents a place to store a single integer and can be used wherever an integer variable can be used
  • For example, an array element can be assigned a value, printed, or used in a calculation:
  • The values held in an array are called array elements
  • An array stores multiple values of the same type – the element type
  • The element type can be a primitive type or an object reference
  • Therefore, we can create an array of integers, an array of characters, an array of String objects, an array of Coin objects, etc.
  • In Java, the array itself is an object that must be instantiated
  • Definitions using new

    • The above statement will:
    • allocate block of memory to hold 7 doubles
    • initialize block with zeros
    • returns the address of the block
    • create a handle called scores
    • store address of the block in scores


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com