Server Side Kotlin-Array

Search for a command to run...

No comments yet. Be the first to comment.
Synchronization is one of the most important concepts in Linux kernel development. When multiple kernel threads access a shared resource simultaneously, improper synchronization can lead to race condi

Modern software systems often separate control logic from high-performance execution logic. This design is common in networking, distributed systems, operating systems, storage engines, and embedded s

Introduction Engineering software often combines multiple programming languages to leverage their individual strengths. A common approach is to implement computational algorithms in native C or C++ wh

Deadlocks are one of the most common synchronization problems encountered in operating systems and concurrent programming. Although the concept is frequently introduced in textbooks, observing it insi

Memory and resource allocation are fundamental operations inside the Linux kernel. Whether assigning device IDs, managing CPU masks, allocating interrupt vectors, or tracking hardware resources, the k

Arrays in Kotlin are used to store multiple values having the same data types in a group.
Arrays are represented by a pair of square brackets []. The values in an array are known as elements and their position is defined by index ( or indices). Each element in an array is separated by commas (,).
Array follows index-based access. The index is nothing but the position of the elements of an array. The index always starts with 0.
Kotlin has wide support for primitive arrays. There are dedicated arrayOf methods for the following types: double, float, long, int, char, short, byte, and boolean. To represent arrays of primitive types, Kotlin provides a number of separate classes, one for each primitive type. For example, an array of values of type Int is called IntArray. For other types, Kotlin provides ByteArray, CharArray , BooleanArray, and so on. All of these types are compiled to regular Java primitive Array.

The constructor of the type takes a size parameter and returns an array initialized with default values for the corresponding primitive type
>>> val parray = IntArray(5)
The factory function ( intArrayOf for IntArray and others) takes a variable number of values as arguments and creates an array taking those values.
>>> val parray = intArrayOf(0, 0, 0, 0, 0)
The constructor takes a size and lambda is used to initialize each element.
>>> val parraysqr = IntArray(5) { i -> (i+3) * (i+3) *(i+3) }
>>> println(parraysqr.joinToString())

To create an Object array in Kotlin, we use the arrayOf() function and place the values in a comma-separated list inside it.
>>> val languages = arrayOf("javascript", "kotlin", "python", "ruby")
//Optionally we can provide a data type as follows:
>>> val languages = arrayOf<String>("javascript", "kotlin", "python", "ruby")
The arrayOfNulls() function can be used to create an array of a given size filled with null elements.
>>> val nularr = arrayOfNulls<Int>(4)
The Array constructor takes the size of the array and lambda, and initializes each array element by calling the lambda.
>>> val letters = Array<String>(26) { i -> ('z' - i).toString() }
>>> println(letters.joinToString(""))

Kotlin provides get() and set() member functions to get and set the value at a particular index.
>>> val languages = arrayOf<String>("javascript", "kotlin", "python", "ruby")
>>> println( languages.get(3))
>>> languages.set(3, "php")
An array is a collection of the same data items stored under a single name. Array follows index-based access. The index always starts with 0. There are two types of Arrays in Kotlin and each type is having 3 ways to create Arrays.
(code tested on kotlin REPL Kotlin version 1.7.21 (JRE 11.0.17+8-post-Ubuntu-1ubuntu220.04))
