LESSON 3 Flashcards

(31 cards)

1
Q

Java provides a data structure, the__, which stores a fixed-size sequential collection of elements of the same type. An __ is used to store a collection of data, but it is often more useful to think of an __as a collection of variables of the same type.

A

Array

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

To declare an array, define the variable type with __

A

square brackets

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

Declaring an array does __it. In order to store values in the array, we must initialize it first

A

not initialize

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

Different ways to initialize an array:

A
  1. Initializing an array without assigning values
  2. Initializing an array after a declaration
  3. Initializing an array and assigning values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An array can be initialized to a particular size. In this case, the default value of each element is 0.

A
  1. Initializing an array without assigning values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An array can also be initialized after declaration.
Note: When assigning an array to a declared variable, the new keyword must be used.

A
  1. Initializing an array after a declaration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

An array can also be initialized during declaration.
Note: __an array during initialization, the size is not specified.

A
  1. Initializing an array and assigning values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Each variable in Java array is also called an __

A

“element”

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

Each element in the array has an __ .You can access each element in the array via its __.

A

Index (a number)

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

You can use the ___ in a Java array just like if they were ordinary variables.

A

Elements

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

You can read their value, assign values to them, use the elements in ___ as parameters to method calls.

A

calculations and pass specific elements

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

The indexes of elements in a Java array always start with _ and continue to the number 1 below the size of the array.

A

0

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

Java provides an attribute 1.__ that
determines the 2.__.

A
  1. length
  2. length of an array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Every array has an __ property whose value is the size of the array.

A

in-built length

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

The length property can be invoked by using the __ followed by the array name. We can find the length of int[], double[], String[], etc.

A

dot (.) operator

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

__ is an array of type int that can hold 5 elements.

17
Q

The __ is a variable that stores the length of an array.

18
Q

Note that __ determines the maximum number of elements that the array can contain or the capacity of the array. It does not count the elements that are inserted into the array. That is, __ returns the total size of the array. For arrays whose elements are initialized at the time of its creation, length and size are the same.

19
Q

SORTING ELEMENTS IN AN ARRAY

A

•Using For Loops
•Using The Sort method

20
Q

You can use__ to traverse the array and compare adjacent elements while traversing and putting them in order.

A

Using For Loops

21
Q

The Arrays class of ‘java.util’ package provides the __that takes an array as an argument and sorts the array. This is a direct __ and you can sort an array with just one method call.

A

Using The Sort method

22
Q

The __provided by ‘java.util.Arrays’ class is a very simple and faster way to sort an array. This method can sort elements of primitive types as well as objects that implement the comparable interface.

23
Q

The general prototype of sort method is as follows:

A

A. Sort Numeric Array In Ascending Order
B. Sort Numeric Array In Descending Order
C. Sort String Array in Alphabetical Order

24
Q

The first demonstration is sorting of number array in __ using sort methods. As already mentioned, by default the sort method sorts the array in__. Thus, to sort a numeric array in __, you just have to call the method on the array in question.

A

A. Sort Numeric Array In Ascending Order

25
The next task is to sort the numeric array in __. To do this the sort method is provided with a second argument.‘__’ that sorts an array in __.
B. Sort Numeric Array In Descending Order Collections.reverseOrder()
26
Just like numeric arrays, you can also sort string array using the sort function. When you pass the string array, the array is sorted in ascending __. To sort the array in descending__, you should provide the Collections interface method reverseOrder () as the second argument.
C. Sort String Array in Alphabetical Order
27
Types of array
SINGLE DIMENSIONAL ARRAY MULTIDIMENSIONAL ARRAY
28
A array means it has only one value for every index. i.e. memory location.
SINGLE DIMENSIONAL ARRAY
29
Now come to a __. We can say that a 2d array is an array of array. A __ is mostly used to store a table-like structure.
MULTIDIMENSIONAL ARRAY
30
Array has two pairs of square brackets. first one for row and the second one for the column. Do remember that in array if we need to get any value we are using index number associated with it.
2 dimensional
31
After creating an array object it is time to __ it.
Initializing 2d Array