Array in JAVA

when you create some application, one of integral part is array. array is one of object which almost used when you create a program. array usually used to store multiple object, such as integer, string, double, etc. in java, you can store another object that you create by yourself, such as book object that has string of title, string of author, etc. so, in this article, i just want to write detail (my version :)) about array which i found from jls ebook (Java Language Specification). you can download it from oracle website for free.

this is it :

  • Array Types
  • Array Variables
  • Array Creation
  • Array Access

Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion and become int values.

  • Array Store Exception
  • Array Initializers

[sourcecode language=”css”]
class Test {
public static void main(String[] args) {
int ia[][] = { {1, 2}, null };
for (int[] ea : ia) {
for (int e: ea) {
System.out.println(e);
}
}
}
}
[/sourcecode]

  • Array Members
  1. length
  2. clone [overrides the method of the same name in class Object and throws no checked exceptions.]
  3. All the members inherited from class Object
  • Class Objects for Arrays

[sourcecode language=”css”]
class Test {
public static void main(String[] args) {
int[] ia = new int[3];
System.out.println(ia.getClass());
System.out.println(ia.getClass().getSuperclass());
}
}
[/sourcecode]

output :
class [I
class java.lang.Object
note :
where the string “[I” is the run-time type signature for the class object “array with component type int”.

  • An Array of Characters is Not a String

i emphasize you that i copy this list base on jls documentation and myself explanation. so, if you found mistake about my explanation or list, you may contact me!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro