Basic Scala + Collection Classes Flashcards

(15 cards)

1
Q

T or F. val x: Int = 1 is equivalent to val x = 1

A

True

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

Does the ++ operator exists in scala?

A

No

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

What type is y in the expression val y = if x > 0 then 1?

A

Unit

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

What is the type of an assignment statement in Scala?

A

Unit

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

T or F. Break & continue don’t exist in Scala.

A

True

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

T or F. daysToHours(hoursInDay = 153, days = 3) is valid syntax but ordering of parameters must be correct.

A

False, is valid even if ordering incorrect.

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

Distinguish between def, val and lazy val.

A

Def = evaluate every time function used.
val = evaluate immediately on definition
lazy val = evaluated only first time it is used (not defined), possibly never.

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

Give a basic run down of collection class hierarchy.

A

Traversable -> Iterable -> {Set, Seq, Map}

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

Difference between array and arrayBuffers.

A

arrayBuffers dont need to know what size before runtime.

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

What are Vectors?

A

They are indexed like arrays but are immutable.

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

How are multidimensional arrays implemented in Scala.

A

Array[Array[Int]]

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

How would you create Map[String, Int]?

A

val scores = Map(“Mike” -> 3, “Lucy” -> 5, “Alex” -> 7)

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

Does var/val, mutability/immutability affect object or reference.

A

Var/val = reference
Mutability/Immutability = object

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

What is a List?

A

An immutable sequence of objects of the same type. Linked list.

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

Difference between vector and list.

A

Vector implemented as array so fast access. Bad for pattern matching.
List implemented as linked list so slow access. Great for pattern matching.

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