deleteLater Flashcards
1st slide
So today we are going to be learning about I raise an array list.
And in this presentation, I’ll be going over what an array is, how to use it and using array list API
This is commonly used in automation, so it’s imperative that we understand this concept.
So let’s get started.
So what is an array?
So, so far we’ve only worked with the primitive variables and you know when we use primitive variables.
arrays
The primitive variables you have worked with so far are designed to hold one value at a
time.
next
An array, however, is an object that can store a group of values, all of the same type.
Creating and using an array in Java is similar to creating and using any other type of object:
You declare a reference variable and use the new key word to create an instance of the array
in memory.
an example of how data is stored in array
This is like an example of how data is stored in array.
So if an array is, so if in the size of the array is 10, it means that this array is capable of holding 10 items.
So you can also say that this is the size of the array and when you declare an array size it must be like a positive integer.
It must not be negative integer, so the way it works is when you design an array of 10 elements and then like in programming language like when you store things in Java in arrays it starts with zero, not one.
So the first value gets stored in first index which is 0 and then the second value gets stored in this this here and then the third and then the 4th and then as you can see it only goes to 9.
This is also known as subscript or you can also call them indices, but the point is that each element is assigned to a number known as a subscript, or you can call index or also indices, and a subscript is used as an index to pinpoint a specific element within an array.
If i wanted to access the first index, i do 0. the second is 1
This is how to declare the size array
An array’s size declarator must be a non-negative integer expression.
You cannot make the size to be -5, if you do that it will give you error.
subscript
each element is assigned a number known
as a subscript. A subscript is used as an index to pinpoint a specific element within an array.
The first element is assigned the subscript 0, the second element is assigned 1, and so forth.
performs bounds checking
Java performs array bounds checking, which means that it does not allow a statement to
use a subscript that is outside the range of valid subscripts for an array. For example, the
following statement creates an array with 10 elements. The valid subscripts for the array
are 0 through 9.
enhanced for loop
The enhanced for loop is designed to iterate once for every element in an array. Each time
the loop iterates, it copies an array element to a variable. Let’s look at the syntax more
closely as follows:
* dataType elementVariable is a variable declaration. This variable will receive
the value of a different array element during each loop iteration. During the first loop
iteration, it receives the value of the first element; during the second iteration, it
receives the value of the second element, and so on. This variable must be of the same
data type as the array elements, or a type that the elements can automatically be converted
to.
* array is the name of an array on which you wish the loop to operate. The loop will
iterate once for every element in the array.
* statement is a statement that executes during a loop iteration.
arraylist
ArrayList is a class in the Java API that is similar to an array and allows
you to store objects. Unlike an array, an ArrayList object’s size is
automatically adjusted to accommodate the number of items being stored
in it.
advantages
An ArrayList object is similar to an array of objects, but offers many
advantages over an array. Here are a few:
* An ArrayList object automatically expands as items are added to it.
* In addition to adding items to an ArrayList, you can remove items as well.
* An ArrayList object automatically shrinks as items are removed from it.