Arrays, Java inbuilt Lists, Autoboxing and Unboxing Flashcards

1
Q

Array

A
  • a data structure that allows you to store multiple values of the same type into a single variable
  • the default values of numeric array elements are set to zero
  • arrays are zero-indexed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain code:

int [ ] reference = new int [number]

A
  • new keyword is used to create the array and initialize the array elements to their default values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain code:

scanner. nextInt();
scanner. nextLine();

A
when you have the nextInt() method, it only consumes the number and leaves the "enter" behind (in the buffer). 
The nextLine() method will clear that "enter" from the buffer first.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ArrayIndexOutOfBoundsException

A

xxx

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

[ ]

A

square brackets [ ] would indicate an array

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

{ }

A
  • code block

- array initializer block

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

Reference type vs Value type

A
  • the primitive data types are predefined
  • the reference data type refers to where data is stored. They contain the reference/addresses of dynamically created objects.
  • once we create a reference variable, they only store the address of these values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write the general syntax to create and declare an ArrayList object

A

ArrayList < type > reference = new ArrayList<> ();

  • the type can be primitive like int, double, boolean
  • it also can be String, the objects you create
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ArrayList

A
  • the ArrayList class is a resizable array.

- it can be found in java.util package

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

Write the general syntax to declare, declare and instantiate, declare and instantiate and initialize an array

A

type [ ] reference;
type [ ] reference = new type [size];
type [ ] reference = new type [size] {array literal}

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

autoboxing

A

automatic conversion of primitive types to the object of their corresponding wrapper class

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

unboxing

A
  • the reverse process of autoboxing

- automatically converting an object of a wrapper class to its corresponding primitive type

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

LinkedList

A
  • a linear data structure that contains a sequence of nodes, in which each node contains data and a pointer (reference) to another node.
  • singly linked list and doubly linked list
  • to access our desired value, we would have to traverse the linked list and continue accessing the next value of each node until arriving at it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write the syntax of enhanced for loop in Java?

A
for (declaration: expression) {
    // statements
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to create an ArrayList instance?

A

ArrayList < type > reference = new ArrayList < >;

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

Compare ArrayList and LinkedList

A

ArrayList class

  • it uses a dynamic array to store the elements
  • it supports the storage of all types of objects
  • manipulating ArrayList takes more time due to shifting the memory bits
  • it implements a List interface so it acts as a list
  • it works better when the application demands storing the data and accessing it

LinkedList class

  • it uses a doubly linked list to store the elements.
  • it supports the storage of all types of objects.
  • manipulating LinkedList takes less time compared to ArrayList because there is no shifting memory bits. The list is traversed and the reference link is changed
  • it implements both the List interface and the Deque interface so it acts as a list and a deque
  • it works better when the application demands manipulation of the stored data