ARRAY Flashcards
(32 cards)
is a container object that holds a fixed number of values
of a single type.
array
The – of an array is established when the array is created. After creation, its – is fixed.
length, length
Array store – values of the same type.
multiple
Array uses —based indexing( first elements at index 0)
ZERO
Array has a – size, meaning it cannot grow or shrink –.
fixed, dynamically
Array elements are stored in – memory locations.
contiguous
Declare with –.
datatypes identifier[]={“val1”, “val2”, “val3”,…..”valn”};
values
Declare with –.
datatypes identifier[] = new datatype[size]
no values
Accessing and Modifying Array Elements use – to access elements (arr[index]).
indexing
Index starts from 0 and goes up to length –.
- 1
class is a resizable array, which can be found in the java.util package.
ArrayList
The difference between a built-in array and an ArrayList in Java, is that the
size of an array – (if you want to add or remove elements to/from
an array, you have to create a new one). While elements can be added and removed
from an ArrayList whenever you want.
cannot be modified
To access an element in the ArrayList, use the – method and refer to the index number
get()
To modify an element, use the – method and refer to the index number
set()
to remove an item, use the – method and refer to the index number: cars.remove(0);. To remove all the elements in the ArrayList, use the – method
remove(), clear()
– to find out how many elements an ArrayList have, use the –
method
size()
this is used to sort elements from a-z.
Collections.sort()
is a sequence of character treated as single unit such as “Hello World”.
String
String –, once a string is created it cannot be changed. None of its methods changes the string.
immutable
The common way to create a string by using string – or using quotes and assign it in a variable;
literals,
When the input type is not what the program expects.
InputMismatchException
When you do invalid math operations, like dividing by zero.
ArithmeticException
When you try to access an array index that doesn’t exist.
ArrayIndexOutOfBoundsException
When you try to use an object that is null
NullPointerException