Java ArrayList 🧾

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey how's it going everybody it's bro hope you're doing well and in this video i'm going to teach you guys all about arraylists in java so sit back relax and enjoy the show if you find this video helpful please remember to like comment and subscribe your support will help keep this channel running all right well welcome back ladies and gentlemen in this video i'm going to be explaining arraylists an arraylist is a collection it's a type of resizable array elements can be added and removed after the compilation phase which you cannot normally do with standard arrays however they only store reference data types and i'll give you a few examples so these are the steps in order to create an arraylist first we type array list pay attention to the capitalization the a and the l are both capital then we need a pair of angle brackets and we're going to list the reference data type within the angle brackets let's say we're storing an arraylist of food so we will create an arraylist that will store some strings for the names of food now if you need to store primitive values like an integer a double a character you need to use the wrapper class so for example if we needed to store integers within an arraylist we would not place int we would use the appropriate wrapper class and type integer so we're going to be storing strings which are already reference data types so let's call this arraylist food equals new array list angle brackets we're going to list the data type again of string parentheses semicolon and we'll need an import so at the top of our program outside the class import java.util.arraylist we now have an arraylist called food that will store strings so how can we add values to our arraylist well there is a function to do that that is the add function and in order to use the add function type in the name of the arraylist dot add and we can add a string so let's add a few food items let's add pizza to the first element followed by i'm going to copy this hamburger and hotdog so let's display all the elements of our arraylist and we can do that using a for loop so for parentheses curly braces and then we will need an index int i will set the sequel to zero we'll continue this for loop as long as i is less than food and normally with arrays you would use dot length but with array lists we use dot size and we are going to increment our index by one and then in order to display or retrieve one of the elements of our array we will use the get function and let's put this within a print line statement food dot get and then we are going to list the index of i so this will display all of the food that is in our arraylist pizza hamburger and hot dog now let's discuss a few useful methods of array lists the first useful method is the set method food dot set so we can set a value at a certain index let's say at index zero currently we have pizza at this index we will replace this value with maybe sushi and now within our arraylist if we display all of the elements using our for loop we now have sushi hamburger and hotdog so our pizza value has been replaced with sushi because we used the set method so we can also remove a value at a certain index using the remove method food dot remove let's say we would like to remove our hotdog that is at element number two and now we only have sushi and hamburger and last but not least we can use the clear method to clear our arraylist food.clear and we no longer have any elements within our arraylist of food because we cleared it we ate all the food all right everybody so that is arraylists in java if you would like a copy of all this code i will post all of this in the comments down below please don't forget to do me a favor and smash that like button drop a comment down below and subscribe if you'd like to become a fellow bro
Info
Channel: Bro Code
Views: 18,196
Rating: undefined out of 5
Keywords: java arraylists, arraylists java, java arraylist, arraylist java, java arraylist tutorial, java arraylists tutorial, arraylists tutorial java, arraylist tutorial java, arraylists java explained, arraylist java explained, array vs arraylist, arraylist vs array, arraylist methods, java arraylist implementation
Id: 1nRj4ALuw7A
Channel Id: undefined
Length: 4min 32sec (272 seconds)
Published: Mon Oct 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.