14 videos
80 minutes
In this video we will see a very important concept is that of, Arrays, or arrangements, I will call them, Arrays, I explain what is, Arrays, and we have seen that to store information on variables, we have to declare and put what type it is, and how it will be called, but imagine for example, you want save, lots of data, you have to see everything the same, and we'll give you an example, imagine that you are making an application for a train and you want
namely, how many passengers are occupying each of the wagons of the train, then what would you do? ... you say, int wagon 1 and say how many are there, then you say, int wagon 2 and say how many are in the car 2, and so on, with all the cars, well so far with what we know of this course, that is the option we have, however, for that they are, Arrays, one Arrays, is a set of data, which are all associated with the same name, but
in that data, in that set, you say how many variables, it's like you want to combine in there, that is, for example, you know that the train has 5 cars, you can create one, arrays of integers with five boxes for which you, there in each, save the settings as if you had 5 variables in one, that is, arrays, a combination ... How is that done? Well, I would do the following, we would, int wagons, and here we would
to open and close brackets [] to indicate that what we do is one, Arrays, which is a combination and then say, = new int, and here in the brackets tell how many boxes will have our, Arrays, for example say you have 5, this is to declare a structure, Arrays, we do is what we will save in, how are you going to call, with brackets, and then say, = new int, because it is whole, if String, would String, type
data, and then here we will save many. Thus we have five variables with the same name, all are called wagons, so now the question is: How do we access each of the five? How to tell which one we want to give the data? If all the same name, then using this shtick which is the index, or position that each of them has, and you explain ... what we just created, it is like saying the following, we have created, I will
and put a comment, each + I write, it is like a variable, one, two, three, four ... five. Here I have five variables, this would each one of the boxes of the cars that we have created, how the named Java? ... well, name them as follows, to the first, named a zero, with the next one to the next with a two, then a three, and finally a four, it is true that there are five, are five, but begins
name them from zero, so that if I here want to say how many passengers are in the car No. 1, we would say so, 'wagons' which is named after I put the brackets [], and say what position you want to save the information, if for example want to save the information, 'zero' and then say, how much there In, for example, in this car we will say that there are 23 passengers, because there it is! Boxcar is = 23 passengers. Wagons in the zero position, if we
fill in the rest of wagons, but we have to say, how many are in each of the positions, Arrays, changing the index, the index is this shtick is here that tells me, in which one am accessing, so in the car number 2, the car number two, would be the No. 1 index, say for example that there are 15 passengers in the car three, which is the No. 2 index, for example 56, in the car number four, 1 passenger is alone, and the
No. 5 van 21 wagon, as is logical, here decimal numbers can not give, because there is no decimal passengers, so we have that whole, you see? So now I have all the cars, now want to show how much is in one of them, I can do the following, I put it here, System.out.println. And here I say: 'wagons Two for example, and get like position, many passengers in the car three, 'and here when I compile, I said 56 passengers in the car 3, because here I have
said get me the information that is in the number two index, which index number 2 is: 1, 2, 3rd wagon. You see? So here I can already access each values, Arrays, did you see? And not to declare five variables, or if the train has eight carriages, 8 variables, no! Only one, which is called all the same, but with the index, either because this concept, Arrays, is central Java, has a lot of power, so it is important that if
well mastered, the next video we will go one step further.
About the Author
Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.