Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
No Result
View All Result
Home Kotlin

 Kotlin Arrays (Lesson 9 PDF)

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
 Kotlin Arrays (Lesson 9 PDF)

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains and is now an official language for Android development. Kotlin is designed to be concise, expressive, and safe. It is also interoperable with Java, which means that you can use Kotlin and Java code together in the same project.

Kotlin

You might also like

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin Functions & Classes (Lesson 11 PDF)

 Kotlin Arrays (Lesson 9 PDF)

Overview about the Lesson

In this lesson, we’ll cover the basics of Kotlin arrays, including how to create and initialize arrays, how to access and modify array elements, and how to traverse arrays.

The Content Of The Lesson

The lesson is divided into the following sections:

  • Creating and initializing arrays
  • Accessing and modifying array elements
  • Traversing arrays
  • Multidimensional arrays
  • Array methods
  • Array performance

Why This Lesson

Arrays are a fundamental data structure in programming, and Kotlin provides excellent support for working with arrays. By the end of this lesson, you’ll have a solid understanding of Kotlin arrays and how to use them in your programs.

Kotlin Arrays: Create, Access and Loop

The PDF introduces arrays step by step. Here are the operations you will use most, with their output.

Creating arrays

fun main() {
    val fruits = arrayOf("Apple", "Banana", "Cherry")
    val numbers = intArrayOf(5, 10, 15)
    val zeros = IntArray(4)               // [0, 0, 0, 0]
    val squares = Array(5) { i -> i * i } // [0, 1, 4, 9, 16]
    println(squares.joinToString())       // 0, 1, 4, 9, 16
}

Use intArrayOf, doubleArrayOf and friends for numbers: they avoid boxing and are faster than Array<Int>.

Reading and changing elements

fun main() {
    val fruits = arrayOf("Apple", "Banana", "Cherry")
    println(fruits[0])        // Apple (indexes start at 0)
    fruits[1] = "Mango"       // arrays have a fixed size but mutable elements
    println(fruits.size)      // 3
    println(fruits.last())    // Cherry
    println("Mango" in fruits) // true
}

Accessing an index that does not exist (fruits[3]) throws ArrayIndexOutOfBoundsException. Use getOrNull(3) when the index might be invalid.

Looping through an array

fun main() {
    val scores = intArrayOf(80, 95, 70)
    for (s in scores) println(s)
    for ((index, s) in scores.withIndex()) println("$index: $s")
    for (i in scores.indices) println(scores[i])
}

Useful array functions

FunctionExampleResult
sum / averageintArrayOf(80,95,70).sum()245
max / minintArrayOf(80,95,70).max()95
sortedintArrayOf(3,1,2).sorted()[1, 2, 3] (a List)
contains / in5 in intArrayOf(1,5)true
filterintArrayOf(1,2,3,4).filter { it % 2 == 0 }[2, 4]
joinToStringarrayOf("a","b").joinToString("-")a-b

Printing an array

println(fruits) prints something like [Ljava.lang.String;@1b6d3586, the array’s memory reference. Use fruits.joinToString() or fruits.contentToString() to print the elements.

Array or List?

Arrays have a fixed size. If you need to add or remove items, use a MutableList (mutableListOf("a","b")), which most Kotlin code prefers. Arrays are mainly used for performance-sensitive code, for main(args) and when calling Java APIs.

Practice exercise

Find the average of five test scores and count how many are above 75.

fun main() {
    val scores = intArrayOf(68, 82, 91, 74, 77)
    println(scores.average())             // 78.4
    println(scores.count { it > 75 })     // 3
}

Frequently Asked Questions

How do I compare two arrays in Kotlin?

a == b compares references, not contents. Use a.contentEquals(b) to compare elements.

Can a Kotlin array hold different types?

An Array<Any> can, but it is rarely a good idea. Prefer a data class or a list of a single type.

Continue the course

← Previous: Lesson 8: When, While, Break & Continue  |  Next: Lesson 10: For Loops & Ranges →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output
  3. Lesson 3: Comments & Variables
  4. Lesson 4: Data Types
  5. Lesson 5: Operators
  6. Lesson 6: Set Operations & Grouping
  7. Lesson 7: Booleans & If…Else
  8. Lesson 8: When, While, Break & Continue
  9. Lesson 9: Arrays (you are here)
  10. Lesson 10: For Loops & Ranges
  11. Lesson 11: Functions & Classes
  12. Lesson 12: Classes, Objects & Constructors
  13. Lesson 13: Class Functions & Inheritance

Conclusion

In this blog post, we’ve covered the basics of Kotlin arrays, including how to create and initialize arrays, how to access and modify array elements, and how to traverse arrays. We’ve also explored some advanced topics, such as multidimensional arrays, array methods, and array performance. With this knowledge, you’ll be well-equipped to work with arrays in your Kotlin programs.

Download From Link

You can download the lesson from the following link:

From Here

Tags: AndroidJavaJVMKotlinProgrammingtechnology
Previous Post

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Next Post

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

Ahmed Elhozayen

Ahmed Elhozayen

Related Posts

Kotlin Class Functions & Inheritance (Lesson 13 PDF)
Kotlin

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)
Kotlin

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Functions & Classes (Lesson 11 PDF)
Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)
Kotlin

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)
Kotlin

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

by Ahmed Elhozayen
October 11, 2026
Next Post
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

October 11, 2026
Excel guide for data analytics learners

Excel for Data Analysis PDF

October 11, 2026

Categories

  • apple
  • Canon
  • Data Analysis
  • Excel
  • Finance
  • ios
  • Kotlin
  • Marketing
  • MBA
  • Samsung
  • Software Tutorials
  • Technology

Don't miss it

20 Essential Excel Formulas Every Data Analyst Must Know in 2026
Data Analysis

20 Essential Excel Formulas Every Data Analyst Must Know in 2026

May 18, 2026
Excel guide for data analytics learners
Excel

Excel for Data Analysis PDF

October 11, 2026
The Ultimate Guide to Financial Modeling PDF
Excel

The Ultimate Guide to Financial Modeling PDF

October 11, 2026
The Ultimate Excel Handbook PDF
Excel

The Ultimate Excel Handbook PDF

October 11, 2026
𝟓𝟎 𝐄𝐱𝐜𝐞𝐥 𝐒𝐡𝐨𝐫𝐭𝐜𝐮𝐭 𝐊𝐞𝐲
Excel

50 Excel Shortcut Key PDF: Streamline Your Workflow

March 21, 2025
Most Useful Excel Keyboard Shortcuts For Windows and Mac OS
Excel

Most Useful Excel Keyboard Shortcuts for Windows and Mac OS PDF

March 21, 2025
Connect4Techs Tech

Practical, free guides on Excel, data analysis, finance, business and programming — written to help you learn faster and work smarter.

Follow on Facebook

Topics

  • Excel
  • Kotlin
  • MBA
  • Finance
  • Data Analysis
  • Apple
  • Technology
  • Software Tutorials

Latest articles

  • 20 Essential Excel Formulas Every Data Analyst Must Know in 2026May 18, 2026
  • Excel for Data Analysis PDFAug 31, 2025
  • The Ultimate Guide to Financial Modeling PDFApr 19, 2025

Company

  • About us
  • Contact
  • Privacy Policy
  • Terms of Use
  • IT Certification PDFs
© 2026 Connect4Techs. All rights reserved. Privacy · Terms · Contact
No Result
View All Result
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact