Passing arrays as function parameter in java
1. Assigning objects to the array
of reference before the calling of function:
public static void main(String[]
args) {
byte[] arr=new byte[3];
byte[] x= calc(arr);
// in this case x = arr ( not null);
}
public byte[] calc (byte[] arr)
{
//do something here.
return arr;
}
2. Assigning objects to the array
of references in the called of function:
public static void main(String[]
args) {
byte[] arr=null;
byte[] x= calc(arr);
// in this case x = null
}
public byte[] calc (byte[] arr)
{
arr = new byte[3];
//do something here.
return arr;
}
No comments:
Post a Comment