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

Where should I use var and where val ?

expert

Why do we use companion object as a kind of replacement for Java static fields in Kotlin?

middle

What is the equivalent of Java static methods in Kotlin?

Bình luận

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

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