saif Active member
| Subject: Program to explain some behaviors of an array Wed Mar 17, 2010 2:01 pm | |
| class array_try { private static int arr[][]=new int[5][5]; private static int arr2[][]=new int[6][7]; public static void main(String args[]) { System.out.println("Dsplaying details of arr[][]"); System.out.println("row="+arr.length); System.out.println("column="+arr[0].length); arr2[5][6]=50; arr=arr2; System.out.println("arr[5][6]="+arr[5][6]); System.out.println("New row="+arr.length); System.out.println("New column="+arr[0].length); } }
OUTPUT row=5 column=5 arr[5][6]=50 New row=6 New column=7 Dsplaying details of arr[][] row=5 column=5 arr[5][6]=50 New row=6 New column=7
CONCLUSION
you may change the array size if desired |
|
NITIN BHUWANIA Active member
| Subject: Re: Program to explain some behaviors of an array Wed Mar 17, 2010 8:47 pm | |
| what is this for???
what do we have to do in this program?? |
|
saif Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 10:02 am | |
| this program shows that you may change the array size if desired and can store the value of an array in another array by arr1=arr2 |
|
Rabi
| Subject: @saif Thu Mar 18, 2010 1:35 pm | |
| hey guys dont u think..dat this logic is nt suitable by writing arr=arr2; u r only making the reference of arr point towards arr2 u r nt changing the array length bt u r creating two copies of same arr2 so u loose the original arr |
|
G-7 Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 2:20 pm | |
| whatever...! But the point that saif wants top bring out is that arrays are mutable...!! and that it can be copied..! as he has just initialised one position to 50. So..it doesnt matter if we just copied it the ordinary way...!! |
|
saif Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 2:21 pm | |
| and yes we will loose the original array arr... |
|
G-7 Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 2:22 pm | |
| saif..what is the property that u wish to present over here.? |
|
saif Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 2:32 pm | |
| you have rightly guessed.I just wanted to show that "arrays are mutable" and we can do arr1=arr2; we can do same thing with objects.... |
|
G-7 Active member
| Subject: Re: Program to explain some behaviors of an array Thu Mar 18, 2010 2:36 pm | |
| yea man...good program..! |
|
Sponsored content
| Subject: Re: Program to explain some behaviors of an array | |
|
|
|