To clarify those who don't understand what does cars.length and cars[i].length means, basically: cars.length: detect how many instances/objects are there in the row of the 2D array and cars[i].length: detects how many instances/objects are there in the column of the 2D array
@RestedAura2 you mean the opposite right? cars.length : no of objects in column (vertically/ up to down) or Basically determine no of rows cars[i].length : no of objects in row (horizontally/ left to right) or Basically determine no of columns i was super confused on this topic. correct me if I'm wrong
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
When I was watching your 2d array tutorial it reminded me of Inception and the concept of dreams within a dream. Sounds stupid but it actually works lmao.
Great vid, although it would have been nice for you to also include how you can access the data within a 2D array and why you would wanna use a 2D array in the first place.
Why have cars[i].length in the nested for loop? It doesn't seem to be necessary since it will always be the length of the array anyways. Side note: Love these tutorials, they have all been excellent!
Yes it is not necessary if each row has same number of columns as number of rows, i.e. square array. Let's say if there are 3 rows total, and each row has 3 columns/elements in them, then cars.length = 3, which will work for this case. But, let's say if the array has 3 rows and 2 columns/elements in each row, this logic will break, since again cars.length will be equal to 3, and we know, the third column doesn't exist in any row. So, it's necessary to use cars[i].length as each row is a seperate array in itself. Also, each row can have varying number of columns/elements, which makes it extremely necessary to use the logic. For example consider this array: Tesla, BMW, Audi, Hyundai Mercedes, Volkswagen Range Rover, Buggati, Toyota First row has 4 elements, second row has 2 elements, while the third row has 3 elements.
Bro, I literally type this out and I get a 1D aka a list. I've been thinking about this for at least 15 minutes without an answer. EDIT: Never mind. I'm a fucking moron. In the last line I wrote sysout + ctrl + space and that's 'System.out.println();' but I need 'System.out.print();'. The 'println' makes a whole new line for each bundle of text forcing the text into a list format. Holy shit I'm happy I'm a stubborn person and figured this out.
cars.length is showing the number of instances that there is on that row. In this case that would be 3. That's why the loop keeps going as long as 'i' is lower than cars.length. cars.length = 3 'i' keeps increasing by 1 until it's no longer less than 3. So it goes like: 0, 1, 2. And then it stops, because 3 !< 3, it's equal. The same way, when you type it as cars[i].length, you are getting the number of instances on that column. On this example, that number is still 3, but if you added another row, it would be 4. Using this kind of loop, you make sure you're passing through every instance on your array. It's checking the length of every row on the first loop, and the length of every column on the nested loop. I hope this made sense, if you have any question, ask again and I'll try to clarify it.
@@JusticeBeaver619 Imagine as if he made a variable of Columns and Rows, and assigned the values to each, you could have called that variable in the place of using cars.lenght or cars[i].lenght, which essentially means, "if i is less than Columns" or "if j is less than rows"
As i undestand, that's used to read the size of the array. So the as long as counter doesn't surpass the size of the array, it will continue to loop around. Once, the counter matches the size or 'length' of the array, it will stop.
I had the same question lol, but i think it's because it's a 2D array.i'm not sur but i think it's to say the length of the row not the column. I will let Bro answer this :p
Idk whats happening to my Ide but it isnt becoming 2d but instead its a list idk why but i copy pasted ur code and it become 2d then I typed it again and its still a list :T
Last line needs to be System.out.print(cars[i][j]+" "); NOT System.out.println(cars[i][j]+" "); . Look for the 'ln' before 'print'. That's causing spaces inbetween each bundle of text.