I am going to share a simple thing that I found today.
I was studying about Java Multidimensional Arrays (aka: 2D Arrays) and I knew it before since I saw Multidimensional Arrays when learning C++. But haven't used it much.
When I was doing studying i found a code like this (This isn't the actual code, I wrote one my myself in this post)
Code: Select all
for (int a = 0; a <array1.length; a++ ){
for (int b = 0; a <array1[a].length; a++ ){
System.out.println(array1[a][b]);
}
}
Note: I didn't add array declaration code here.
I was able to understand most of it like. The 2 for loops and .length
But I didn't get what these do
andarray1.length
because they were working in another way and not like what I was thinking.array1[a].length
After experimenting a little, I found out that, Unlike normal arrays, like if we use .length in a normal array (one dimensional array) we get number of elements as the result. But in 2D arrays if we use
we get how much rows are there as the result and if we want to find out how much elements in each row we need to use thisarray1.length
array1[a].length
So here's how I understood that
Not that much big one, But I hope to share for some one who got confused
Thanks