Dynamic Arrays 🌱

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

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

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

    I forgot to add a get() method for random access 🤦‍♂️
    I've included that in the code posted here...
    public class Main{

    public static void main(String[] args) {
    DynamicArray dynamicArray = new DynamicArray(5);

    dynamicArray.add("A");
    dynamicArray.add("B");
    dynamicArray.add("C");

    //System.out.println(dynamicArray.get(0));
    //dynamicArray.insert(0, "X");
    //dynamicArray.delete("A");
    //System.out.println(dynamicArray.search("C"));

    System.out.println(dynamicArray);
    System.out.println("size: " + dynamicArray.size);
    System.out.println("capacity: " + dynamicArray.capacity);
    System.out.println("empty: " + dynamicArray.isEmpty());
    }
    }
    public class DynamicArray {
    int size;
    int capacity = 10;
    Object[] array;

    public DynamicArray() {
    this.array = new Object[capacity];
    }
    public DynamicArray(int capacity) {
    this.capacity = capacity;
    this.array = new Object[capacity];
    }

    public Object get(int index) {
    return array[index];
    }

    public void add(Object data) {

    if(size >= capacity) {
    grow();
    }
    array[size] = data;
    size++;
    }

    public void insert(int index, Object data) {

    if(size >= capacity) {
    grow();
    }
    for(int i = size; i > index; i--) {
    array[i] = array[i - 1];
    }
    array[index] = data;
    size++;
    }

    public void delete(Object data) {

    for(int i = 0; i < size; i++) {
    if(array[i] == data) {
    for(int j = 0; j < (size - i - 1); j++){
    array[i + j] = array[i + j + 1];
    }
    array[size - 1] = null;
    size--;
    if(size

    • @K86-j4y
      @K86-j4y 3 года назад

      Can u make a swift all in 1 course plssss

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

      You forgot the clear() method,
      public static void clear(){
      array=null;
      size=0;
      }
      thank you sir for your explanation

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

      Practicing...
      import java.util.*;
      public class Main
      {
      public static void main(String[] args) {
      DynamicArray dynamicArray = new DynamicArray();
      //System.out.println(dynamicArray.capacity);
      dynamicArray.add("1");
      dynamicArray.add("2");
      dynamicArray.add("3");
      dynamicArray.insert(0,"0");
      dynamicArray.delete("")
      System.out.println(dynamicArray);
      System.out.println("size: " +dynamicArray.size);
      System.out.println("capacity: " +dynamicArray.capacity);
      System.out.println("empty: " +dynamicArray.isEmpty());
      }
      }
      ***************
      public class DynamicArray{
      int size;
      int capacity = 15;
      Object[] array;
      public DynamicArray(){
      this.array = new Object[capacity];
      }
      public DynamicArray(int capacity){
      this.capacity = capacity;
      this.array = new Object[capacity];
      }
      public void add(Object data){
      if(size >= capacity){
      grow();
      }
      array[size] = data;
      size++;
      }
      public void insert(int index, Object data){
      if(size >= capacity){
      grow();
      }
      for(int i = size; i > index; i--){
      array[i] = array[i-1];//Shifting all elements to the right
      }
      array[index] = data;
      size++;
      }
      public void delete(Object data){
      for(int i = 0; i < size; i++){
      if(array[i] == data){
      for(int j = 0; j < (size - i + i); j++){
      array[i + j] = array[i + j + i];
      }
      array[size - 1] = null;
      size--;
      if(size

  • @s.w.5169
    @s.w.5169 3 года назад +43

    I hope you will continue this series. It's just amazing!

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

      Thanks! I will be, this playlist will probably have close to 20-ish videos

  • @BN-cr3el
    @BN-cr3el 3 года назад +10

    Best videos on Data Structure & Algorithm. Thank you for making them!

  • @MarshGames
    @MarshGames 2 года назад +7

    This is so sick. Thank you for taking the time to explain and build a working ArrayList. I love people like you that explain things with both graphics and code. I have 0 questions about a topic when you put it together this organized. And the code in the comments (and the commented explanations)... 😙👌

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

    great LECTURE.
    still need to see this over again. love your lectures.

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

      Np! Thanks for watching Fahad!

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

    Currently having java as main programming language in my college, and your videos are really helpful. Thanks!

  • @phyusinlin574
    @phyusinlin574 Год назад +2

    Thank you so much for providing this enlighting tutorial.

  • @SomduttaSomSinha
    @SomduttaSomSinha 3 года назад +6

    What's the difference between making instantiating array as Object[] array and making the class able to hold generic objects using Java generics (i.e. public class DynamicArray)? If we use Object[], wouldn't we have to cast elements to its actual type when retrieving them (e.g. int first = (int) array[0])?

    • @wintutorials2282
      @wintutorials2282 9 месяцев назад

      TU delft??

    • @DalandanReal
      @DalandanReal 16 дней назад

      So it's technically arrayList if we use generics instead ???

  • @malekmousa1193
    @malekmousa1193 3 года назад +7

    Can you make a video on Java Streams. I would really appreciate it ❤️

  • @AbhijeetKumar-cm3jh
    @AbhijeetKumar-cm3jh 3 года назад +2

    Yayy, Was waiting for it, your explanations are really great, thanks :)

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

    very glad to see your views increasing :) you deserve it and I'm happy that people finally found this gem.

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

    Thanks for this video. It was interesting to see you implement a custom dynamic list rather than just using Java's ArrayList.

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

    You bring back the joy of code. Feel's good to see relaxing tutorials just solving problems🌻

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

    i love your videos, they're so easy to watch and understand. thank you.

  • @DalandanReal
    @DalandanReal 16 дней назад

    Thank you now I know how arrayList really works

  • @shubhamsonar1816
    @shubhamsonar1816 3 года назад +7

    ❤️Thanks bro for.....................

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

    In add method, we have to put if condition after size++ for condition of size==capacity

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

    Thanks bro! Very good and easy to understand explanations

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

    Hey bro this tutorial was long and BOOM THANKS BEEN HERE SINCE THE ROBOT SOUNDTRACK🤣

  • @Naz-yi9bs
    @Naz-yi9bs 3 года назад

    Don't know Java yet trying to understand it with little bit of Python knowledge I have, thank you for the video.

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

    Such as amazing video. This helped me out heaps! thanks. Subscribed !

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

    That was valuable ! Thank you sir for the great work👍🏾

  • @ismailibrahim-z2j
    @ismailibrahim-z2j Месяц назад

    thankyou bro code your content really made my life easy

  • @torekalanae_
    @torekalanae_ Год назад +2

    in the .toString() (assuming that you didn't use StringBuilder), wouldn't it be much more efficient and faster by using this?:
    String string = "";
    for(int i=0;i0){
    string += ", ";
    }
    string += array[i];
    }
    return "[" + string + "]";
    instead of doing this?:
    for(int i=0;i

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

    You Can do this in delete method to be easy to understand
    public void delet(Object data) {
    for (int i = 0; i < size; i++) {
    if (array[i]== data){
    for(int j =i ; j < size; j++){
    array[j]= array[j+1];
    }
    array[size-1]= null;
    size--;
    }
    }
    }

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

    I was coming at this from a C angle... I just noticed you weren't in VS code. Eclipse for Java. Got it.

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

    nice sound and very good lession thank you

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

    Hey, not sure whether am i wrong or not but for the DELETE function, i think we forgot to handle 'what if the DATA happened to be INDEX 0' So maybe we should add an IF statement for when INDEX == 0
    if( i == 0) {
    for (int x = 0 ; x < size ; x ++) {
    array[x] = array[x + 1];
    }
    break;
    }

  • @dre1997ful
    @dre1997ful 3 года назад +4

    I feel like in some instances with coding you just have to accept the information and be like well idk why but it works so it works for me? lol

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

    Hey , your videos are great. I really want you to make all this contents with python as well.

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

    Thanks bro I like a video like this and tutorial KEEP IT UP 💓💓💆‍♂️

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

    You are doing really great!

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

    Love you brooo.from Bangladesh

  • @Muhammadfaisal-kd9kx
    @Muhammadfaisal-kd9kx Год назад

    thankyou bro great content as always

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

    i'm just waiting for full-course video ,,,, offline is better to watch for me. i'v all collection of full. very thank you .... i also reqst to make video on algorithm by easy representation. good DataStructur and Algorithm video is very rare in youTube.

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

    Thank you, great explonation.

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

    Fantastic. Tank you so much!

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

    Thank you. Very useful ;)

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

    hey brocode. Just a tip for your next videos. If you are going to import images in to your project is it possible to make a link in the descriptions to download the same objects? It's pretty annoying or even sometimes impossible to find an image with the same size etc...
    just a tip
    love ur videos:)
    also make new java videos; if you got time;)

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

    Sweet video, tanks!

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

    nice one bro

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

    remember when your channel was 11k subs? me niether Good Job, Keep it up

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

      hey ayman! Yeah it's been a heck of a ride

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

    bro, do you videos for databases, ex: mysql. tnx bro.

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

    Nice Class

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

    I dont understand how
    for(int i = size; i > index; i--) {
    array[i] = array[i - 1];
    }
    works. from my understanding it should push all the values to the left because its subtracting but it pushes them to the right, i have no clue how this works

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

      We are keeping i = size ( i.e,last index +1).
      let's say the size is 4 and we have to insert data in index 2
      when i = 4 ..the data in index 3 (i-1) will get copied in index 4 (i)
      i--;
      now i=3 ...the data in index 2(i-1) will get copied in index 3 (i )
      i--;
      now i = 2 is not greater than index which we have passed in ( which is 2) the loop terminates.
      then we can insert the data like
      array[ 2] = data ;

    • @lyra5349
      @lyra5349 23 дня назад

      @@joa5724 thank you man

  • @Cloud-pc8id
    @Cloud-pc8id 2 года назад +3

    I made this delete method and somehow it worked
    public void delete(Object data) {
    for(int i = 0; i < size; i++) {
    if(array[i] == data) {
    for(int j = i; j < size; j++) {
    array[j] = array[j + 1];
    }
    if(size

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

    Woah cool

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

    I love you bro from Morocco

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

    Can you make tutorial for mips assembly?

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

    Great video!

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

    Why use a dynamic array in C++ when we can give int array[n].
    Dynamic arrays are created when number of data items is unknown.
    But we could also use
    int n;
    cin>>n;
    int array[n];

  • @unknown-rd3kv
    @unknown-rd3kv Год назад +1

    Thanks bro 🫡

  • @pragmaticcoder6910
    @pragmaticcoder6910 9 месяцев назад

    What are the chances of asking to build a dynamic array in FAANG interview? Ideally for me it'll take time to ace this algorithm appropriately.

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

    Helpful!

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

    brilliant👍

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

    Bro please make a series on kivy GUI with python 🙏🙏🙏

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

    Please make some applications on javafx like you made for swing
    And after database please teach artificial intelligence

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

    Thanks, Bro!

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

    Bro i want to watch this playlisy but can u please tell me what are data structures and algorithm.

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

    thank you so much!

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

    good video! ty!

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

    amazing contnet

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

    When you do the insert method, why is the for loop:
    for (int i = size; i > index; i--)
    array[i] = array[i - 1];
    rather than
    for (int i = size + 1; i > index; i--)
    array[i] = array[i - 1];
    if you have an array = {A, B, C, D, null, null}
    size = 4
    So the first for loop would set array[4] = array[3] which is saying the fourth element is equal to C.
    But what happens to D?

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

      i starts at 0.
      array[4] = "null" since it's index 0, 1, 2, 3, 4
      So array[4] = array[3] is correct as it is setting null to D, D to C...... n
      Hope that makes sense

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

      yup and the size kind of is your pointer holding the space for the move to the right

  • @wzup23
    @wzup23 6 месяцев назад

    Dude why does it automatically converts the input to string without calling toString() method? Thanks

  • @BendoubaAbdessalem
    @BendoubaAbdessalem 6 месяцев назад

    java is wierdly similar to c#, i know , it's the other way around but that code is wierdly fimiliar

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

    Hey bro, could you include the source code in C++ also? It would be great.

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

    Pls bring on hcking😊😊

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

    guys its irrevelant but do you know how to scrap live data from web sites (stock, crypto) with c++

  • @Onlinetraining-h7x
    @Onlinetraining-h7x 7 месяцев назад

    Is this program code similar to ArrayList internal code??

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

    thanks bro!

  • @emreotu4464
    @emreotu4464 18 дней назад

    Dynamic Arrays 🌱

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

    bro are your all in one vedios sufficent for start coding for the first time, i mean if i watch all of em

  • @Ankit-ge7yn
    @Ankit-ge7yn 3 года назад

    Android developement tutorial please..🙏🙏

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

    Thanks!

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

    Hyy bro make video on android development. I will appreciate that 💓

  • @yasmineahmedaboeleinin7844
    @yasmineahmedaboeleinin7844 8 месяцев назад

    👍🏻👍🏻

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

    nice

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

    Yaaa boi

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

    Is there any difference in all in one course and other which you gave made separately in same language ?

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

      I compile all the lessons in the playlist into one video. I think the Java course only has 80 videos from the 100 playlist tho

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

      @@BroCodez okk

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

      @@BroCodez so for java I should refer to the playlist ?

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

    random comment

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

    Long time no see

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

    thx

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

    bro in the toString() method you created without calling the method in the main class how did it be automatically called when you printed the dynamic array please reply

    • @rectaalborween8471
      @rectaalborween8471 8 месяцев назад +1

      I might be a bit late lolol
      But to answer your question, this is because println() has an overloaded variant which calls "object.toString()"
      When we write the toString() body all we're actually doing is overloading that method

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

    I don't get how this code works...
    for(int i = 0; i

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

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

    Hey man, I know you're busy and all, but I have a little coding problem I need help with.

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

    I want you to make a tutorial and how to make splash screen in mcp minecraft 1.8.8, if you didn’t do it’s okay! I just tryna find a tutorial how to make a splash screen in mcp minecraft 1.8.8

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

      💆‍♂️🧖‍♀️

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

      I'm actually not familiar with Minecraft mods... at least not yet

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

      @@BroCodez hmm okay 😆

  • @m0lecules
    @m0lecules 11 месяцев назад

    🖖

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

    sweetest

  • @Ankit-ge7yn
    @Ankit-ge7yn 3 года назад

    Question = In java programming..
    Int[ ] [ ] a= {
    {1,2,3},
    {5,6,7},
    {8,9,10}
    };
    And I want to print ,
    1 5 8
    2 6 9
    3 7 10
    (as a output)
    Sir How to print this output, please help ??

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

      It's just like reading through regular 2D array but printout a[j][i] instead of a[i][j]. Hope it helps

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

    Hell yeah I was like 666 very cool.

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

    So why did you get kicked out of heaven?

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

    random comment for u my dude

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

    no translate for me!! my E is bad so i can't understand what are u Saying

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

      They should auto-translate, it might take a while to generate since this video is longer than usual

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

      @@BroCodez thanks, i very like your videos. I hope u will make videos.
      +1 respect 😂😂😂

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

    7:54

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

    13.01

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

    Random comment down below - checked

  • @AR-rg2en
    @AR-rg2en Год назад

    Random comment

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

    😏

  • @anasjaidi1894
    @anasjaidi1894 12 дней назад

    ودي الكود واتس اب