Array class in java code example
Example 1: import arrays java
import java.util.Arrays;
Example 2: array objects java
obj array[] = new obj[10];
for (int i = 0; i < array.length; i++) {
array[i] = new obj(i);
}
Example 3: java array object
Class obj[]= new Class[array_length]
Example 4: java array object
class ObjectArray{
public static void main(String args[]){
Account obj[] = new Account[2] ;
obj[0].setData(1,2);
obj[1].setData(3,4);
System.out.println("For Array Element 0");
obj[0].showData();
System.out.println("For Array Element 1");
obj[1].showData();
}
}
class Account{
int a;
int b;
public void setData(int c,int d){
a=c;
b=d;
}
public void showData(){
System.out.println("Value of a ="+a);
System.out.println("Value of b ="+b);
}
}