Java Array : Array « Java Source And Data Type « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Java Source And Data Type » Array 
1.16.1.Java Array
Arrays can hold primitives or objects, but the array itself is always an object.
When you declare an array, the brackets can be to the left or right of the variable name.
It is not legal to include the size of an array in the declaration.
An array of objects can hold any object that passes the IS-A (or instanceoftest for the declared type of the array. 

To create and use an array, you must follow three steps:

   1. Declaration
   2. Construction
   3. Initialization

public class MainClass {

  public static void main(String[] argvs) {
    int[] ints;
    ints = new int[4];

    for (int i = 0; i < ints.length; i++) {
      ints[i= i;
    }

  }
}


It is never legal to include the size of the array in your declaration. 

public class MainClass{
    public static void main(String[] argv){
        int[5scores;
    }
}
Syntax error on token "5", delete this token
1.16.Array
1.16.1.Java Array
1.16.2.Declaration tells the array's name and type
1.16.3.Declares a two-dimensional array
1.16.4.The square brackets can come before or after the array variable name.
1.16.5.All elements of an array must be of the same type allowed by polymorphism.
1.16.6.Declaring an Array of Primitives, and declaring an Array of Object References
1.16.7.We can also declare multidimensional arrays, which are in fact arrays of arrays.
1.16.8.A method that returns an array of doubles
1.16.9.Array size is specified via the new keyword.
1.16.10.It is legal to specify size with a variable rather than a literal
1.16.11.Declaration and construction may be performed in a single line
1.16.12.When an array is constructed, its elements are automatically initialized to their default values.
1.16.13.Arrays must be declared before you use them.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.