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.
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
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"
hey bro i have a question.. when we use 2D arrays and we should use 2D arrays instead of a normal array and can we use linked list instead of 2D array or matrix ?
You use 2D arrays when you want an array of arrays. Technically, you could just make a hashmap or just create separate arrays, or even store the contents of a 2D array into a regular array, but sometimes it’s just a bit cleaner to use 2D arrays, I guess (specifically when representing matrices)
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.
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.
@TheFakeViRuZz good answer but it's not complete, i think we need to understand the difference between the "Index (i)" and the "Length (cars.length)". When you declare the array of 3 string ( ex : String[ ] cars = new String [3] ) : 1. The length is 3 ( cars.length, returns 3 ) 2. The index goes from "0" to "2" ( cars[0], cars[1], cars[2] )
i found the solution, was supposed to import java.util.Arrays; and then at the end System.out.println(Arrays.toString(cars[i])); had to print it that way
Here's the code from the video. Try copying and pasting it and see if that output is still the same: public class Main { public static void main(String[] args) { // 2D array = an array of arrays String[][] cars = { {"Camaro","Corvette","Silverado"}, {"Mustang","Ranger","F-150"}, {"Ferrari","Lambo","Tesla"} }; /* cars[0][0] = "Camaro"; cars[0][1] = "Corvette"; cars[0][2] = "Silverado"; cars[1][0] = "Mustang"; cars[1][1] = "Ranger"; cars[1][2] = "F-150"; cars[2][0] = "Ferrari"; cars[2][1] = "Lambo"; cars[2][2] = "Tesla"; */ for(int i=0; i
public class Main {
public static void main(String[] args) {
// 2D array = an array of arrays
String[][] cars = {
{"Camaro","Corvette","Silverado"},
{"Mustang","Ranger","F-150"},
{"Ferrari","Lambo","Tesla"}
};
/*
cars[0][0] = "Camaro";
cars[0][1] = "Corvette";
cars[0][2] = "Silverado";
cars[1][0] = "Mustang";
cars[1][1] = "Ranger";
cars[1][2] = "F-150";
cars[2][0] = "Ferrari";
cars[2][1] = "Lambo";
cars[2][2] = "Tesla";
*/
for(int i=0; i
Wow
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
Thanks bro, the loop now makes sense to me, I didn't understand how the j int was smaller than the i int while they were both zero.
thx bro
@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
@@maximizer174bruh, you got it mixed up. Columns are verticles (top to bottom)
Rows are horizontal (left to right)
@@transfertransfer986 isn't that what i said? 😅
System.out.println("Great Video");
Boolean comment = true;
If(comment = true)
{System.out.println("Amen to that");}
@@godcomplex1929error
@@godcomplex1929 your comment is messed up
I can't believe I understood this! You have excellent teaching skills.
have been watching ur vids the last few weeks since starting CS in college. they’ve helped so much, thank you
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
Amazing video! Watching all of these to refresh and learn!
Your video helped me a lot! It was the only tutorial that solved my problem. Thank you!
This is such a helpful and well explained video! Thanks!
Nice quick and easy explanation. Great job!
Your tutorials are the best!
2d arrays understood completely. 16th. Thank you, ma Bro Sensei!
best teacher ever.. good job bro
I love watching these videos before class.
Thanks for the help man, this video helped me a lot.
AMAZING ! BEST TUTORIALS HANDS DOWN !
This is important video for multi-dimentional array.
Ooo nice, I wanted one of these.
Good video, thanks for sharing
simple & great! thanks
i have a java final Friday, so thanks for this video!
This video was so useful!!! Thank you Bro!
Thanks , best explanation !
Awesome 👏
You are the best bro!
I did this with pokemon:
public class Array2Ds {
public static void main(String[] args) {
String[][] pokemon = {{"Bulbasaur", "Ivysaur", "Venusaur"},
{"Charmander", "Charmeleon", "Charizard"},
{"Squirtle", "Wartortle", "Blastoise"}
};
//This also works but define it at the top already: String[][] pokemon = new String[3][3];
// pokemon[0][0] = "Bulbasaur";
// pokemon[0][1] = "Ivysaur";
// pokemon[0][2] = "Venusaur";
// pokemon[1][0] = "Charmander";
// pokemon[1][1] = "Charmeleon";
// pokemon[1][2] = "Charizard";
// pokemon[2][0] = "Squirtle";
// pokemon[2][1] = "Wartortle";
// pokemon[2][2] = "Blastoise";
for (int i = 0; i < pokemon.length; i++) {
System.out.println();
for (int j = 0; j < pokemon.length; j++) {
System.out.print(pokemon[i][j]+ " ");
}
}
}
}
nice! That's a good visualization
i love pokemon too
my code is little diffrent but thNK U BRO
love aesthetic code@@BroCodez
Bro it helped me tommorrow is my exam and was clulessly watching this now
Thanks bro, keep it up💪🏿💪🏿💪🏿
Okay now its etched in my brain Thanks dude :)
Thank u Ms.Bro, I'm from Jordan.
very nice explained
Awesome👏👏😊😊
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.
I have smashed that like button so hard, there is a hole is my screen now. Worth it!
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.
Great Job!
Thanks for the lesson
Thank you very much for this video
you are the man!
Good job
thanks, it's so helpful
amazing
cool cars bro
Thanks you!!
Very usefull
You are getting me through QA class man
Nice.
So
Public static void main is method
(String [] args) is array???
you are the best
Nice
Thank you so much 💙💙💙
thx a lot for your help
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.
@@udayrajoriyaa thanks for the great explanation!
Valuable bro
thx 4 vid bro !
great
how would you bubble sort this 2d array
thanks for this
bro where chalk up u been, it is so cool
I don’t know what’s wrong with my console, it would display everything straight down and not on the side like his. I need help
thanks you very much
thank you very much
So we can't remove an item within this array?
I kiss your head, dear bro code ! LOVED it ! Thank you !
I have a question and would really appreciate anyone's help. I'm not understanding what the "length" is supposed to do in i
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.
Why it should be "j
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
Thanks, Bro! ☕
Thanx bro
thanks bro
Gracias brooo
what is cars.length representive of? like does that mean that I increases until all letters of cars are met or until all the cars are met? thanks
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.
@@albertocasanovalaras3153 got it. But can you please explain why we use cars[i].length instead of just cars.length . The value is 3 in both cases
@@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"
❤️👌
Thank you Bro
THX!
Thank you Bro, you gave me an idea how I can solve my code problems 👍🙏
useful
Thanks
ty bro
thank you
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
Thank!!
how to check if the matrix is quare : matrix[n][n]
hey bro i have a question.. when we use 2D arrays and we should use 2D arrays instead of a normal array and can we use linked list instead of 2D array or matrix ?
You use 2D arrays when you want an array of arrays. Technically, you could just make a hashmap or just create separate arrays, or even store the contents of a 2D array into a regular array, but sometimes it’s just a bit cleaner to use 2D arrays, I guess (specifically when representing matrices)
@@perseusgeorgiadis7821 whats the use arrays you can simply write that is print option
thanks
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.
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.
🐐
👍
Yeah!
bro code please can you explain collection interface and harshmap
i miss 3d dorritos
6 ferbruar l watched
bro!!
Bro helps
Someone help me.... why it should be ( int i=0; i
@TheFakeViRuZz good answer but it's not complete, i think we need to understand the difference between the "Index (i)" and the "Length (cars.length)".
When you declare the array of 3 string ( ex : String[ ] cars = new String [3] ) :
1. The length is 3 ( cars.length, returns 3 )
2. The index goes from "0" to "2" ( cars[0], cars[1], cars[2] )
@@shinkanade1552 thanks!!!!!
😀
Back to the good microphone
Sysout (cars[i][j]+" ");
And
(Int j = 0; j>cars[i].length; j++)
Brooo what does those line of codes mean, what's "[ ]"
I would like to be a fellow bro, lol
cant figure out why am i getting this output
Ljava.lang.String;@7de26db8
please help
i found the solution, was supposed to import java.util.Arrays; and then at the end
System.out.println(Arrays.toString(cars[i])); had to print it that way
Here's the code from the video. Try copying and pasting it and see if that output is still the same:
public class Main {
public static void main(String[] args) {
// 2D array = an array of arrays
String[][] cars = {
{"Camaro","Corvette","Silverado"},
{"Mustang","Ranger","F-150"},
{"Ferrari","Lambo","Tesla"}
};
/*
cars[0][0] = "Camaro";
cars[0][1] = "Corvette";
cars[0][2] = "Silverado";
cars[1][0] = "Mustang";
cars[1][1] = "Ranger";
cars[1][2] = "F-150";
cars[2][0] = "Ferrari";
cars[2][1] = "Lambo";
cars[2][2] = "Tesla";
*/
for(int i=0; i
comments for stats!