Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

lists-arrays-kotlin

Lists and arrays

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Lists and arrays: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Teams still ship Lists and arrays in Kotlin codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Lists and arrays in contexts like: Android apps, Spring services, and shared KMP modules.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Kotlin collections mirror Java lists but add read-only vs mutable interfaces: List vs MutableList. Arrays use Array<T> or primitive arrays like IntArray when you need fixed-size performance.

Lists and arrays

val names = listOf("Ada", "Bob")
val mutable = mutableListOf(1, 2, 3)
val arr = intArrayOf(10, 20, 30)

listOf returns an immutable list; mutableListOf allows add/remove. Prefer lists over arrays unless interoping with Java APIs that require arrays.

Common operations

  • map, filter, forEach, sumOf
  • Indexing: names[0], first(), last()
  • Ranges: names.slice(0..1)

Important interview questions and answers

  1. Q: List vs MutableList?
    A: Read-only interface prevents accidental mutation at compile time; same backing list may still be mutable if cast unsafely.
  2. Q: Array vs IntArray?
    A: IntArray avoids boxed integers; Array<Int> boxes on JVM.

Self-check

  1. Which factory creates an immutable list?
  2. When prefer IntArray over Array<Int>?

Pitfall: Do not confuse Array and List at APIs—prefer List in public signatures.

Interview prep

listOf vs mutableListOf?

listOf returns read-only interface; mutableListOf allows mutation.

Array vs List?

Prefer List in APIs; Array is fixed-size and Java-interop heavy.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • List vs MutableList?
  • Array fixed size?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump