Java 2D arrays 🚚

Поделиться
HTML-код
  • Опубликовано: 27 июл 2024
  • Java 2D multidimensional arrays tutorial explained
    #Java #2D #arrays #multidimensional
  • НаукаНаука

Комментарии • 171

  • @BroCodez
    @BroCodez  3 года назад +126

    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

  • @RestedAura2
    @RestedAura2 Год назад +116

    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

    • @misfire32
      @misfire32 10 месяцев назад +3

      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.

    • @hussinmomen5256
      @hussinmomen5256 7 месяцев назад +1

      thx bro

    • @maximizer174
      @maximizer174 3 месяца назад +1

      @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

    • @transfertransfer986
      @transfertransfer986 2 месяца назад

      ​@@maximizer174bruh, you got it mixed up. Columns are verticles (top to bottom)
      Rows are horizontal (left to right)

    • @maximizer174
      @maximizer174 2 месяца назад

      @@transfertransfer986 isn't that what i said? 😅

  • @erneztoyo
    @erneztoyo 3 года назад +161

    System.out.println("Great Video");

    • @Sssamaa-c8w
      @Sssamaa-c8w 11 месяцев назад +15

      Boolean comment = true;

    • @godcomplex1929
      @godcomplex1929 7 месяцев назад +4

      If(comment = true)
      {System.out.println("Amen to that");}

    • @christiangalagar9213
      @christiangalagar9213 3 месяца назад

      ​@@godcomplex1929error

    • @lobitu3423
      @lobitu3423 Месяц назад

      ​@@godcomplex1929 your comment is messed up

  • @JuliHoffman
    @JuliHoffman 2 года назад +28

    I can't believe I understood this! You have excellent teaching skills.

  • @dolemerchant69
    @dolemerchant69 8 месяцев назад +4

    have been watching ur vids the last few weeks since starting CS in college. they’ve helped so much, thank you

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Год назад +5

    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

  • @fieldsfury
    @fieldsfury 2 года назад

    Amazing video! Watching all of these to refresh and learn!

  • @danchavyn
    @danchavyn 2 года назад

    Your video helped me a lot! It was the only tutorial that solved my problem. Thank you!

  • @youngdumbguitarist5348
    @youngdumbguitarist5348 Год назад +1

    This is such a helpful and well explained video! Thanks!

  • @rr3nn638
    @rr3nn638 3 года назад +5

    Nice quick and easy explanation. Great job!

  • @cesara9747
    @cesara9747 2 года назад

    Your tutorials are the best!

  • @honoredegg
    @honoredegg 2 года назад +2

    2d arrays understood completely. 16th. Thank you, ma Bro Sensei!

  • @dillonpaul1498
    @dillonpaul1498 Год назад +1

    best teacher ever.. good job bro

  • @davidbolduc4378
    @davidbolduc4378 2 года назад

    I love watching these videos before class.

  • @vedmahant7776
    @vedmahant7776 Год назад +1

    Thanks for the help man, this video helped me a lot.

  • @DesiHabibi
    @DesiHabibi 2 года назад

    AMAZING ! BEST TUTORIALS HANDS DOWN !

  • @medjl6083
    @medjl6083 3 года назад +2

    This is important video for multi-dimentional array.

  • @noah77
    @noah77 3 года назад +2

    Ooo nice, I wanted one of these.

  • @ascar66
    @ascar66 Год назад

    Good video, thanks for sharing

  • @haykmanukyan5462
    @haykmanukyan5462 2 года назад +1

    simple & great! thanks

  • @emachine003
    @emachine003 Год назад

    i have a java final Friday, so thanks for this video!

  • @supernovic99
    @supernovic99 Год назад

    This video was so useful!!! Thank you Bro!

  • @nirvomind
    @nirvomind 3 года назад

    Thanks , best explanation !

  • @jeyhunaliyev1765
    @jeyhunaliyev1765 3 года назад

    Awesome 👏

  • @eugenemolchan5141
    @eugenemolchan5141 3 года назад

    You are the best bro!

  • @IceBeam93
    @IceBeam93 3 года назад +14

    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]+ " ");
    }
    }
    }
    }

    • @BroCodez
      @BroCodez  3 года назад +3

      nice! That's a good visualization

    • @d_36_priyanshuurwate65
      @d_36_priyanshuurwate65 2 года назад +2

      i love pokemon too
      my code is little diffrent but thNK U BRO

    • @user-ud6bi6nv6d
      @user-ud6bi6nv6d 10 месяцев назад

      love aesthetic code@@BroCodez

  • @uc8xo
    @uc8xo 10 месяцев назад

    Bro it helped me tommorrow is my exam and was clulessly watching this now

  • @sihleeundefined1208
    @sihleeundefined1208 3 года назад

    Thanks bro, keep it up💪🏿💪🏿💪🏿

  • @Clarara-is9li
    @Clarara-is9li 4 месяца назад

    Okay now its etched in my brain Thanks dude :)

  • @-omarabusnineh5174
    @-omarabusnineh5174 3 года назад +1

    Thank u Ms.Bro, I'm from Jordan.

  • @loopify3905
    @loopify3905 3 года назад

    very nice explained

  • @trickysachin
    @trickysachin 2 года назад

    Awesome👏👏😊😊

  • @mycake1515
    @mycake1515 10 месяцев назад

    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.

  • @shyam.upadhyay
    @shyam.upadhyay 2 года назад +1

    I have smashed that like button so hard, there is a hole is my screen now. Worth it!

  • @BrokenG-String
    @BrokenG-String 6 месяцев назад

    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.

  • @coreywoodring3905
    @coreywoodring3905 4 месяца назад

    Great Job!

  • @yevgenomelchenko732
    @yevgenomelchenko732 Год назад

    Thanks for the lesson

  • @justinbanza4751
    @justinbanza4751 2 года назад

    Thank you very much for this video

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    you are the man!

  • @dew6739
    @dew6739 2 года назад

    Good job

  • @zari_723
    @zari_723 2 года назад

    thanks, it's so helpful

  • @mithunbabbira
    @mithunbabbira 3 года назад

    amazing

  • @soumelee5661
    @soumelee5661 Год назад

    cool cars bro

  • @jackepra8026
    @jackepra8026 Год назад

    Thanks you!!
    Very usefull

  • @jasonfenstermaker4
    @jasonfenstermaker4 5 месяцев назад

    You are getting me through QA class man

  • @huuloc8719
    @huuloc8719 2 года назад

    Nice.

  • @D14R
    @D14R Год назад

    So
    Public static void main is method
    (String [] args) is array???

  • @relaxjam1952
    @relaxjam1952 2 месяца назад

    you are the best

  • @percivalgebashe4376
    @percivalgebashe4376 Год назад

    Nice

  • @ghoggaliabdou4222
    @ghoggaliabdou4222 3 года назад

    Thank you so much 💙💙💙

  • @kirillutsenko9306
    @kirillutsenko9306 2 года назад

    thx a lot for your help

  • @bradleydeans192
    @bradleydeans192 2 года назад +4

    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!

    • @udayrajoriyaa
      @udayrajoriyaa Год назад +8

      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.

    • @bibi.98x
      @bibi.98x 10 месяцев назад

      @@udayrajoriyaa thanks for the great explanation!

  • @ardcodelover
    @ardcodelover Год назад

    Valuable bro

  • @bekturasanbekov1979
    @bekturasanbekov1979 Год назад

    thx 4 vid bro !

  • @zinebjinari7893
    @zinebjinari7893 2 года назад

    great

  • @mensahtribeadventures2630
    @mensahtribeadventures2630 2 года назад

    how would you bubble sort this 2d array

  • @omersond4891
    @omersond4891 3 года назад

    thanks for this

  • @witecki_
    @witecki_ Год назад

    bro where chalk up u been, it is so cool

  • @blueking5739
    @blueking5739 2 года назад

    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

  • @phiphongnguyen3352
    @phiphongnguyen3352 2 года назад

    thanks you very much

  • @user-zq6yx7of5f
    @user-zq6yx7of5f Год назад

    thank you very much

  • @sihleeundefined1208
    @sihleeundefined1208 3 года назад

    So we can't remove an item within this array?

  • @baharehkjani6761
    @baharehkjani6761 10 месяцев назад

    I kiss your head, dear bro code ! LOVED it ! Thank you !

  • @kidhacker1000
    @kidhacker1000 2 года назад

    I have a question and would really appreciate anyone's help. I'm not understanding what the "length" is supposed to do in i

    • @bryanZ17
      @bryanZ17 Год назад +1

      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.

  • @aya2222
    @aya2222 3 года назад

    Why it should be "j

    • @shinkanade1552
      @shinkanade1552 3 года назад

      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

  • @danny.3036
    @danny.3036 3 года назад

    Thanks, Bro! ☕

  • @hadihiwa5690
    @hadihiwa5690 3 месяца назад

    Thanx bro

  • @sairos4057
    @sairos4057 Год назад

    thanks bro

  • @Santiago-iu8mk
    @Santiago-iu8mk 2 года назад

    Gracias brooo

  • @cristiangarciaperez7230
    @cristiangarciaperez7230 2 года назад +2

    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

    • @albertocasanovalaras3153
      @albertocasanovalaras3153 Год назад +3

      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
      @JusticeBeaver619 Год назад +1

      @@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

    • @jironamos7650
      @jironamos7650 Год назад +1

      @@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"

  • @adityaalshi7081
    @adityaalshi7081 2 года назад

    ❤️👌

  • @bartomiejsniadach5795
    @bartomiejsniadach5795 2 года назад

    Thank you Bro

  • @Horatius_23
    @Horatius_23 Год назад

    THX!

  • @kiki.t2094
    @kiki.t2094 2 года назад

    Thank you Bro, you gave me an idea how I can solve my code problems 👍🙏

  • @uclong1176
    @uclong1176 3 года назад

    useful

  • @quanyufeng579
    @quanyufeng579 2 года назад

    Thanks

  • @kidcracker
    @kidcracker 10 месяцев назад

    ty bro

  • @ma8969
    @ma8969 2 года назад

    thank you

  • @mohamedwafik3493
    @mohamedwafik3493 3 года назад +1

    👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏

  • @tamirrozenfeld3572
    @tamirrozenfeld3572 Год назад

    Thank!!

  • @user-km8ee6bm9y
    @user-km8ee6bm9y Год назад

    how to check if the matrix is quare : matrix[n][n]

  • @simon3431
    @simon3431 3 года назад +2

    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 ?

    • @perseusgeorgiadis7821
      @perseusgeorgiadis7821 Год назад

      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)

    • @privateonlyar7
      @privateonlyar7 Год назад

      @@perseusgeorgiadis7821 whats the use arrays you can simply write that is print option

  • @PoorwayTraning
    @PoorwayTraning Год назад

    thanks

  • @tissue.5706
    @tissue.5706 2 года назад +2

    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

    • @ByeBaybe
      @ByeBaybe 2 года назад

      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.

  • @ByeBaybe
    @ByeBaybe 2 года назад

    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.

  • @chiefeveryday7541
    @chiefeveryday7541 2 месяца назад

    🐐

  • @irajgharaee7057
    @irajgharaee7057 3 года назад

    👍

  • @freedom4218
    @freedom4218 Месяц назад

    Yeah!

  • @obiadaoma3840
    @obiadaoma3840 Год назад

    bro code please can you explain collection interface and harshmap

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 года назад

    i miss 3d dorritos

  • @yeliza2350
    @yeliza2350 2 года назад

    6 ferbruar l watched

  • @lukedecum
    @lukedecum 10 месяцев назад

    bro!!

  • @eugenezuev7349
    @eugenezuev7349 3 месяца назад

    Bro helps

  • @aya2222
    @aya2222 3 года назад

    Someone help me.... why it should be ( int i=0; i

    • @shinkanade1552
      @shinkanade1552 3 года назад +2

      @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] )

    • @aya2222
      @aya2222 3 года назад +1

      @@shinkanade1552 thanks!!!!!

  • @grozageorge2887
    @grozageorge2887 Год назад

    😀

  • @Simis999
    @Simis999 Год назад

    Back to the good microphone

  • @koshiredemption
    @koshiredemption 3 года назад

    Sysout (cars[i][j]+" ");
    And
    (Int j = 0; j>cars[i].length; j++)
    Brooo what does those line of codes mean, what's "[ ]"

  • @behrangfattahi9328
    @behrangfattahi9328 2 года назад

    I would like to be a fellow bro, lol

  • @BackTester98-d6d
    @BackTester98-d6d 3 года назад

    cant figure out why am i getting this output
    Ljava.lang.String;@7de26db8

    • @BackTester98-d6d
      @BackTester98-d6d 3 года назад

      please help

    • @BackTester98-d6d
      @BackTester98-d6d 3 года назад

      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

    • @BroCodez
      @BroCodez  3 года назад

      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

  • @danielmilewski7659
    @danielmilewski7659 Год назад

    comments for stats!