Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is the difference between List and Array types?

Câu trả lời

Here is the difference between List and Array types in Kotlin:

List vs Array

  • List is an interface that represents an ordered collection of elements. It provides methods to access, add, and remove elements. Lists can be mutable (MutableList) or immutable (List).

  • Array is a collection of elements of the same type stored in contiguous memory locations. Arrays have a fixed size and cannot be resized. Arrays are mutable by default.

Key Differences

  1. Size:

    • List size is dynamic and can change.
    • Array size is fixed and cannot be changed after creation.
  2. Syntax:

    • List is created using listOf() or mutableListOf() functions.
    • Array is created using arrayOf() function or the array constructor.

...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between suspending vs. blocking?

middle

val mutableList vs var immutableList . When to use which in Kotlin?

junior

What is a primary constructor in Kotlin?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào