Java array of objects 🍱

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

ความคิดเห็น • 138

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +66

    //******************************************************
    public class Main {
    public static void main(String[] args) {

    //Food[] refrigerator = new Food[3];

    Food food1 = new Food("pizza");
    Food food2 = new Food("hamburger");
    Food food3 = new Food("hotdog");

    Food[] refrigerator = {food1,food2,food3};

    //refrigerator[0] = food1;
    //refrigerator[1] = food2;
    //refrigerator[2] = food3;

    System.out.println(refrigerator[0].name);
    System.out.println(refrigerator[1].name);
    System.out.println(refrigerator[2].name);

    }
    }
    //******************************************************
    public class Food {
    String name;

    Food(String name){
    this.name = name;
    }
    }//******************************************************

    • @nikleduc1158
      @nikleduc1158 3 ปีที่แล้ว

      do you have to declare each object in the array like you did with the class ob1 = new class; or is there an easier way to do it like how you can declare int arrays with a simple for loop?

    • @zhaocheng6114
      @zhaocheng6114 2 ปีที่แล้ว

      @@nikleduc1158 You can also do for loops :D

    • @Gjjjj12
      @Gjjjj12 ปีที่แล้ว +1

      The laziest person who copy this text files :)

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 ปีที่แล้ว +10

    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

  • @jetson_
    @jetson_ 2 ปีที่แล้ว +8

    Thank god I can finally organize my fridge.

  • @habtomghebremedhin9829
    @habtomghebremedhin9829 6 หลายเดือนก่อน +1

    You are amazing. Your knowledge and delivering skill is amazing

  • @letstalk6129
    @letstalk6129 ปีที่แล้ว +2

    best videos about programming

  • @dirtygattor9109
    @dirtygattor9109 6 หลายเดือนก่อน +9

    Insane this is 3 years old but has done the best job at explaining how to get this done. Bravo!

  • @lamout847
    @lamout847 2 หลายเดือนก่อน

    Well done explained.

  • @TuckerBryant-m1r
    @TuckerBryant-m1r 5 หลายเดือนก่อน

    Bro is coming in clutch for my cs final tomorrow -- Thank you!

  • @sujayirrinki4915
    @sujayirrinki4915 9 หลายเดือนก่อน

    bro ur an absolute g. I'm watching and following along with every video in ur java playlist and ur seriously filling in gaps. Im gonna use ur vids for the other languages as well. thanks bro

  • @khaledmohamed-hn9nz
    @khaledmohamed-hn9nz 3 ปีที่แล้ว +2

    thanks brother we appreciate your efforts ....best of luck

  • @honoredegg
    @honoredegg 2 ปีที่แล้ว +2

    Completely understood, also with for loop for int numbers this time. 31th. Thank you, ma Bro Sensei!

  • @franklinmaradiaga2401
    @franklinmaradiaga2401 3 ปีที่แล้ว +3

    Wow man, thank you for making this! It really helped

  • @TareqRahaman-u6x
    @TareqRahaman-u6x ปีที่แล้ว

    Great

  • @ChristianRodriguez-tm3jg
    @ChristianRodriguez-tm3jg ปีที่แล้ว

    tyanks for your help

  • @Frosty-od5lu
    @Frosty-od5lu ปีที่แล้ว

    Straight to the point nice video♥️

  • @josefgalindoh
    @josefgalindoh ปีที่แล้ว

    thanx for the help!

  • @millejadecabrera4544
    @millejadecabrera4544 3 ปีที่แล้ว +1

    thanks for this great tutorial series

  • @rohitbharatbhandwalkar8583
    @rohitbharatbhandwalkar8583 ปีที่แล้ว

    Thanks bro

  • @archerx91x60
    @archerx91x60 4 ปีที่แล้ว +1

    Great video bro

  • @TheEvertonDias
    @TheEvertonDias ปีที่แล้ว

    Thanks, Bro!

  • @salvadego7834
    @salvadego7834 2 ปีที่แล้ว

    nice

  • @samirsivan8134
    @samirsivan8134 3 ปีที่แล้ว +3

    i just punched the like button because of One Punch Man.

  • @swarnimraut3841
    @swarnimraut3841 2 ปีที่แล้ว

    Good video as always

  • @elijahkaliya795
    @elijahkaliya795 ปีที่แล้ว

    I loved it

  • @robingloryvideo9064
    @robingloryvideo9064 ปีที่แล้ว

    Thanks🎉🎉🎉😊

  • @yashinani297
    @yashinani297 หลายเดือนก่อน

    Bro code the best

  • @gentle9964
    @gentle9964 ปีที่แล้ว

    noice

  • @mryoloTHEgreek
    @mryoloTHEgreek 6 หลายเดือนก่อน

    lets gooooo

  • @wedihabte6893
    @wedihabte6893 3 ปีที่แล้ว

    Great video

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks

  • @pa-305
    @pa-305 3 ปีที่แล้ว

    best brooo

  • @huuloc8719
    @huuloc8719 2 ปีที่แล้ว

    Nice.

  • @leekbiel
    @leekbiel 2 ปีที่แล้ว

    thanks

  • @valeriesantos507
    @valeriesantos507 7 หลายเดือนก่อน

    Is this array bag?

  • @sudeshsachintha5737
    @sudeshsachintha5737 2 ปีที่แล้ว

    gg

  • @augischadiegils.5109
    @augischadiegils.5109 3 ปีที่แล้ว +1

    Thanks!!

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 ปีที่แล้ว

    thank you bro

  • @majid1885
    @majid1885 2 ปีที่แล้ว

    Thank you Bro

  • @heyykenn9099
    @heyykenn9099 2 ปีที่แล้ว

    how do automatically create an object? what if you allow the user to add a food? how to auto create food4

  • @walt3719
    @walt3719 3 ปีที่แล้ว

    i like food

  • @kemann3815
    @kemann3815 2 ปีที่แล้ว

    Another banger lesson

  • @riccardopaladini8677
    @riccardopaladini8677 2 ปีที่แล้ว

    Perfect!

  • @LongPham-bc4iz
    @LongPham-bc4iz 5 หลายเดือนก่อน

    thank sir

  • @dinushkasandakelum5456
    @dinushkasandakelum5456 3 ปีที่แล้ว

    Can I create an arrayList of objects?

  • @ardcodelover
    @ardcodelover ปีที่แล้ว

    Like and comments

  • @lofilaze
    @lofilaze 3 ปีที่แล้ว

    West Jett

  • @themodestai9603
    @themodestai9603 3 ปีที่แล้ว

    Thank you

  • @alexyakoveno4682
    @alexyakoveno4682 2 ปีที่แล้ว

  • @warrensnook9435
    @warrensnook9435 2 ปีที่แล้ว

    Being formal, isn’t an array of objects technically called an ArrayList?

  • @aruldilip9430
    @aruldilip9430 2 ปีที่แล้ว

    1:41 I don't understand why he is telling, "give a size if we do not plan assigning values right away". I m wondering arrarys are fixed if we declare size at the initialisation, meaning he have plan to assign 3 values at this program hence he is giving size 3. Is there a way he can increase the size dynamically during the run time if the array size is declared at the initialisation? Pls help to advise if I m missing something.

    • @MrJakson112
      @MrJakson112 2 ปีที่แล้ว +3

      Using arraylists, you can change the size during runtime

  • @arikii7385
    @arikii7385 2 ปีที่แล้ว

    But how do I enter new value inside the array object

  • @alialhussain4139
    @alialhussain4139 3 หลายเดือนก่อน

    Thanks, Bro 06/08/2024

  • @ctluwua7695
    @ctluwua7695 3 ปีที่แล้ว

    I need this @ Number 9

  • @meggieelo
    @meggieelo 2 ปีที่แล้ว

  • @karthikks9976
    @karthikks9976 3 ปีที่แล้ว

    thanks. but unable to understand

  • @developerjunior446
    @developerjunior446 3 ปีที่แล้ว

    Where do you study Bro ?

  • @omersond4891
    @omersond4891 3 ปีที่แล้ว

    thanks for the pizza

  • @danielmilewski7659
    @danielmilewski7659 2 ปีที่แล้ว

    comment for stats. thanks bro!

  • @goonwangdu9676
    @goonwangdu9676 3 ปีที่แล้ว

    sup

  • @khalafmanaseer3386
    @khalafmanaseer3386 10 หลายเดือนก่อน

    All ppl in the comments, I understood, Thanks, simple
    Me:Fk me 😢

  • @mateuszszewczyk7985
    @mateuszszewczyk7985 ปีที่แล้ว

    xd

  • @AARTIKUMARI-fe8wx
    @AARTIKUMARI-fe8wx ปีที่แล้ว

    vedio 31

  • @chakmak
    @chakmak 3 ปีที่แล้ว

    need new videos!

  • @doggo2821
    @doggo2821 3 หลายเดือนก่อน

    day 25 of coding

  • @superdose4000
    @superdose4000 3 ปีที่แล้ว

    comment

  • @trevorcarterva
    @trevorcarterva 3 ปีที่แล้ว +34

    You can print all three elements using for loop
    for(int i = 0; i < 3; i++) {
    System.out.println(refrigerator[i].name);

    • @Golosovtalks
      @Golosovtalks 2 ปีที่แล้ว

      No, it didnt work, ive just tried it and I caught an error. I dont know why, buy it doenst work
      P.s this is my code if you want to look at:
      public class Main {
      public static void main(String[] args) {
      Food[] refrigerator = new Food[3];
      Food food1 = new Food("pizza");
      Food food2 = new Food("hamburger");
      Food food3 = new Food("hotdog");
      refrigerator [0] = food1;
      refrigerator [1] = food2;
      refrigerator [2] = food3;
      for (int i = 0; i

    • @keerthanavemula24
      @keerthanavemula24 2 ปีที่แล้ว +4

      @@Golosovtalks You forgot to input the 'name' in the println statement, it shows the address of the food only if u not include name, hope this can helps
      for(int i=0; i

    • @Simis999
      @Simis999 2 ปีที่แล้ว +7

      You can also do that with
      for (Food i: refrigerator) {
      System.out.println(i.name);
      }

  • @FJ-jy1ox
    @FJ-jy1ox 3 ปีที่แล้ว

    thanks

  • @matinmonshizadeh
    @matinmonshizadeh 2 ปีที่แล้ว

    thanks bro

  • @kishanpareek2848
    @kishanpareek2848 2 ปีที่แล้ว +11

    Short, Simple & Effective. Thanks a ton.

    • @jd_6029
      @jd_6029 ปีที่แล้ว +1

      Like a mini skirt

  • @mikebrar7800
    @mikebrar7800 3 ปีที่แล้ว +6

    if you have to create 30+ objects can you use a for loop to instantiate them?

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +14

      Sure, something like this might work
      Car[] cars = new Car[30];
      for(int i = 0; i < 30; i++) {
      cars[i] = new Car();
      }

  • @murats.3481
    @murats.3481 6 หลายเดือนก่อน +2

    These videos are very useful for us beginners. Thank you!

  • @PoorwayTraning
    @PoorwayTraning ปีที่แล้ว

    thanks

  • @valdross283
    @valdross283 11 วันที่ผ่านมา

    Thank you so much, I could understand only watching once. Very good example

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 23 วันที่ผ่านมา

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @elionayzuridasilveira4140
    @elionayzuridasilveira4140 5 หลายเดือนก่อน

    System.out.println("Thank you bro");

  • @ShamimTest
    @ShamimTest 5 หลายเดือนก่อน

    name is in the Food class object. So how it is associating with main class when you are printing the food name.
    Can you explain it please?

  • @cdjosh3568
    @cdjosh3568 4 ปีที่แล้ว +2

    Lets get this bread

  • @eugenezuev7349
    @eugenezuev7349 5 หลายเดือนก่อน

    sometimes it seems that you work as an ambassador of pizza companies. But I doesn't matter, as usual thanks

  • @paia6447
    @paia6447 2 ปีที่แล้ว

    Is pizza your favorite food, cause you mention about it everytime

  • @Lazizbek0005
    @Lazizbek0005 5 หลายเดือนก่อน

    Java seems easier than python

  • @JuliHoffman
    @JuliHoffman 2 ปีที่แล้ว +1

    Thank you! This helped me out.

  • @wallstreetbets7741
    @wallstreetbets7741 2 ปีที่แล้ว

    learnt

  • @mohammadreza1414
    @mohammadreza1414 8 หลายเดือนก่อน

    Thanks, bro.

  • @vik_0584
    @vik_0584 2 ปีที่แล้ว +1

    Thank you dude! Now I can write my homework and know more about classes and objects!

  • @murodmakhmatkulov2681
    @murodmakhmatkulov2681 10 หลายเดือนก่อน

    I am a heroooo

  • @adanskiesabaria
    @adanskiesabaria 4 หลายเดือนก่อน

    nice 1

  • @javierpesaresi311
    @javierpesaresi311 ปีที่แล้ว

    Good goody!

  • @kapebreak
    @kapebreak ปีที่แล้ว

    comment

  • @RockfaxVlog
    @RockfaxVlog ปีที่แล้ว

    Thanks!

  • @percivalgebashe4376
    @percivalgebashe4376 ปีที่แล้ว

    Nice

  • @maciejkaminski8535
    @maciejkaminski8535 3 ปีที่แล้ว

    comment

  • @noamsimantov7614
    @noamsimantov7614 4 หลายเดือนก่อน

    ❤❤❤

  • @aboyiphilippa1136
    @aboyiphilippa1136 5 หลายเดือนก่อน

  • @infiniteaura7792
    @infiniteaura7792 6 หลายเดือนก่อน

    🙃

  • @anjapietralla5767
    @anjapietralla5767 8 หลายเดือนก่อน

    💙

  • @soumelee5661
    @soumelee5661 ปีที่แล้ว

    🍱👍

  • @mateusspencer679
    @mateusspencer679 2 ปีที่แล้ว

    .

  • @fonkat8192
    @fonkat8192 3 ปีที่แล้ว +1

    Excelent video, very helpfull to newbies like me!

  • @RajithSenaratna
    @RajithSenaratna 2 ปีที่แล้ว

    🙏🏻

  • @JehanSaren
    @JehanSaren ปีที่แล้ว

    You are stingy to give, I know you know there is something simpler than that.