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

junior

What is the idiomatic way to remove duplicate strings from array?

middle

What are scope functions in Kotlin?

expert

How does the reified keyword in Kotlin work?

Bình luận

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

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