Arrays Flashcards

1
Q

Arrays Syntax:

A

EX/
String[] names;
String[] names = new String[4];
String[] names = {“Alex”, “David”, “Jennifer”, “Jim”};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Manipulate elements in Array

A

You access an array element by referring to the index number of the element
You can manipulate the value of given index as your need

Example

String[] cars = {“Mercedes”, “BMW”, “Tesla”};
System.out.println(cars[1].toLowerCase());

Expected output:
bmw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Sort and search within an Array

A

sort()
Arrays.sort(numbers);

binarySearch()–> must be sorted first.
Arrays.binarySearch(numbers, 5);
Arrays.binarySearch(numbers);
sout(Arrays.binarySearch(numbers, 5) >=0) // returns true or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Array

DEFINE

A

-Collection that stores multiple data

-It is fixed considering size.
Once you declare it, you cannot change it. (you cannot add or remove elements)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Call an Array that is larger than its size

A

variableName[3] = el4; // ArrayIndexOutOfBoundsException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly