Arrays Flashcards

1
Q

what are Array?

A

A collection of variable of the same data type.
1. An Array in Java is an object
2. An have a fixed size.
3. An array variable referenced a group of data.

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

what null in Java?

A

The value of the object that reference noting.

string name: // null

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

how do you create Array?

A
  1. String[] name; // null
  2. String[] name = new String[4];
    // create 4 array in the
    memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are the default value give to Array when created.

A
  1. 0 for numeric data types
  2. null for reference types
  3. false for boolean types
    4./u0000 for char types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you access Array elements?

A

use brackets and indices
Example:
int[] numbers = new int[4]
numbers[0] = 4;
// this assign 4 to the first element in the array

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

How do we print Array?

A

To print array there are two ways:
1.we use a for loop to print the array
2. we use a for each loop to print the array.

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

what are Anonymous Array?

A

An array without a variable referencing it.
new Scanner(System.in) .nextline();

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

How do we return array from method?

A

int[] numbers = getNumber();
printArray(numbers);
// we are returning an array form the method get numbers into the main method

public static in[] getNumber(){
return int[] {2,3,3,5,6};
}

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

How do pass Array to method

A

Array are passed by reference

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

Exceeding array bounds

A

The indices must be between 0 and length -1.
if you exceed the index of an array you will have an exception message printed to you on the console.

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

what is the Array class in java?

A

A class that contains some static methods that are used with arrays

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

what is the method used to sort array?

A
  1. this method sort the whole Array
    The sort(); method is used to sort Array in Java.
    example: Array.sort(string);
  2. this method sort part of the array.
    sort( Array, fromindex, to index);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the method use to search Array?

A
  1. this method is use to search
    array: binarySearch();

example: binarySearch(numbers,4);
// we are searching for the value of 4 from an array created in the memory.

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

what is the method used to compare array?

A

we use the equal(); method to compare array in java
example:
Array.equal(number1, number2);

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

How do we fill Array with value?

A

we fill array using the fill method.
fill(array, value);
example: fill(number, 4)

fill(array, fromindex, to index, value);

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

How do we print Array?

A
  1. we print array using the toString() method in the array class.
    example: Array.toString(numbers);
15
Q

what is variable length Argument lists?

A

a variable number of arguments can be passed to a method.
example: sum(1,2,);
sum(1,3,8);
sum(1,2,3,4);

16
Q

how do you pass a variable number of arguments to a method

A
17
Q

What are 2D Array?

A

A two dimensional Array is a one dimensional array in which each element is another one dimensional array.
example: int[] [] numbers = new int[4];

18
Q

what are ragged Arrays?

A

A 2D array with rows of different length.
{2,3,4}
{2,3,4,5}
{2,3,4,5,6}

19
Q

In the 2D array the first dimension is what?

A

the first dimension is numbers of row.

20
Q

how do we create a 2D Array?

A

int[][] numbers = new int[4][4];
int[][] numbers;
numbers[4][4];

21
Q

Accessing 2D Array Element

A

the first row index is 0 and the second row index is one(1)
2. we can access the element using the index of row and column.
3. numbers[indexofrow][indexofcolumn]

22
Q

How do we print 2D Array

A
  1. we can print 2D Array by accessing the element by it index and printing it.
    example: numbers[0][0]
    // this print the first element in the first row of the 2D arraya. print Row by Row
    we can use a for loop to print row by row.
    example: for( int i = 0; i < 3(amount of row); i++)
    for(int j = 0; j < 4(amount of colum) j++);
    System.out.println(number[i][j]) // print all the element in the array. i represent the row and j represent the column
    b. column by Column
    we also use a for loop for this
    but i will be the column and j will be the row.
23
Q

what are the other method to print the string representation of array?

A

deepToString(); method is use to print the string represenstation of an 2D array

24
Q
A