Arrays Flashcards
Arrays Syntax:
EX/
String[] names;
String[] names = new String[4];
String[] names = {“Alex”, “David”, “Jennifer”, “Jim”};
Manipulate elements in Array
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
Sort and search within an Array
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
Array
DEFINE
-Collection that stores multiple data
-It is fixed considering size.
Once you declare it, you cannot change it. (you cannot add or remove elements)
Call an Array that is larger than its size
variableName[3] = el4; // ArrayIndexOutOfBoundsException