kotlin

kotlin

How to use fold, foldIndexed, foldRight and foldRightIndexed in Kotlin

If you want to do certain operation on the elements of a list serially, you can use fold(). This method takes one initial value and one operation to perform on the elements serially starting from the provided initial value. fold() performs the operation from left to right. If you want to do it from right to left, you can use foldRight().

Read
kotlin

3 ways to concatenate two collections with distinct elements in Kotlin

In ths tutorial, we will learn how to concatenate two collections with distinct elements. We will use two lists to show you the example. If the first list contains elements (1,2,3,4) and the second list contains (5,6,7), the final list after concatenation will hold (1,2,3,4,5,6,7).

Read
kotlin

Kotlin program to find out the average marks of a list of students

In this Kotlin example program, we will learn how to find the average marks of a list of students. Our program will create one list of few students first and then it will find out the average marks of these students.

Read
kotlin

6 different ways to sort an array in Kotlin

How to sort an array in Kotlin in 6 different ways. We will learn how to sort the array in ascending order, descending order, sort an array of custom objects and sorting a part of the array with examples.

Read
kotlin

Trim leading whitespace characters using trimMargin in Kotlin

Kotlin comes with a really handy function for string to trim leading whitespace characters easily. Known as trimMargin(), the definition of the function is as below :.

Read
kotlin

Kotlin String template : Explanation with Examples

String is a sequence of characters. All strings are of String class. For example, "Hello World" is a string. One more important thing is that String is immutable in Kotlin, i.e. you cann't change any character of a string variable. Kotlin has introduced one new concept for string called string template. It allows us to include one variable or expression to a string. In this tutorial, we will show you how string template works in kotlin with different examples.

Read
kotlin

Kotlin program to reverse an array ( 2 different ways )

In this kotlin programming tutorial, we will learn how to reverse an array using two different ways - Reverse the array, assign this new array to a different variable and reverse an array in place. We are showing these examples for integer arrays, but you can use them for any other arrays with different data types. Let's take a look at the programs.

Read
kotlin

Kotlin example program to find out the largest element in an array

In this Kotlin example program, we will learn how to find out the largest element in an array of numbers. This is a simple example program that will show you how to find out the largest number in an array. Let's take a look at the program :.

Read
kotlin

Kotlin program to find out the factors of a number

In this tutorial, we will learn how to find out the factors of a number in Kotlin. We will show you two different ways- using a for loop and by using a while loop to solve this problem. The programs will print out the factors of a given number one by one. Let's have a look..

Read
kotlin

Data class in Kotlin : Explanation with example

Data class in Kotlin is used mainly for classes that holds only data. Keyword 'data' is used to mark a class data class. These classes cann't be used to define any extra functionalities to a class. By default, this class will provide you few methods. In this tutorial, we will learn about data class in Kotlin , its benifit and use cases.

Read