Java Arrays Flashcards
What are issues with arrays?
The java array does not allow you to add elements. And It can waste the amount of memory. When you set up an array you will allocate some memory space for the amount in the array.
One key item to remember
When you are constructing a data element or anything in java, memory will be allocated and placeholders will be displayed. This is why it is important to when looking at performance of an application.
What is the syntax for the for each method?
for (type var : array)
{
statements using var;
}
What is a stack?
The stack class represents a last in first out stack of objects. it extends the vector class Vector is similar to ArrayList, difference being vector methods are synchronized whereas ArrayList methods are not.
What are the methods to add and remove items from a stack?
Push and Pop
What is a linked list?
All of the nodes are linked together and then can access the address on the next node , One thing to think about it memory efficiency and performance. Linked list will remove items and then will remove the item from the memory.
List interface…
It is the main interface that is used to modify the Array List . The syntax is List countries = new ArrayList<>(). You will notice that the List interface is the type on the left and the ArrayList is the type on the right.
What are some advantages of iterator?
It has more methods that are helpful to go to go through loops.
what is the compareTo method
It is to compare strings or objects. or data types example: Integer x = 3; Integer y =2; x.compareTo(y);
What is one popular method of Iterator?
hasNext() it will determine if there are more elements in the iterator and if there are then it will continue.
What is one common method for collections?
One method is the sort method and can sort collections.