Android Kotlin Tutorial on Static List || List in Kotlin

 

Kotlin Static List :

List of things make your work much easier than maintaining multiple variables isn’t it.List not only help to display/retrieve  values but also store and gather them according their types.

As in the previous tutorials we have seen different data types in variables the same applies in list too..

This part of the tutorial deals with the kotlin static list i.e., fixed values are present inside the list which are defined only once.

Importance:

You might have a question why do we need a kotlin static list? yes may be static list might not be so flexible but kotlin static list has its own importance

1) Faster in processing

2) Few computations require static data for ever so its better to use kotlin static list

**3) In terms of storage static list is much better when compared to dynamic list.

 

Types of List:

We can use list’s with different data types as Integers, Strings, Double, Float…

 

Let’s see sample list declarations..

 

Integer:

Declare a list on Int type in Kotlin we declare Integer as Int

var list = listOf<Int>(1,2,3,4,5,6)

 

String:

Declare a basic list with String datatype

var list = listOf<String>("ab","cd","ef","gh")

 

Double:

Declare a basic list of type Double

var list = listOf<Double>(1.2, 3.4, 1.0, 4.0)

 

 

Types of Operations:

Here i am showing a few operations out of available operations.

1) indexOf

In the given example let us know the index positions

var list = listOf<Int>(1,2,3,4,5,6)

values  (1,2,3,4,5,6)

index   (0,1,2,3,4,5)

 

2) get

Using this method on list we can get the value present in the index position passed

 

3) lastIndex

Using this method we can fetch the last indexed values

 

4) size

Used to know the total size of the values present in the list.

 

For more detailed explanation on kotlin static list go through video tutorial…

 

If you have any query’s in this tutorial on kotlin static list let us know in the comment section below.If you like this tutorial do like and share us for more interesting updates.

 

Show Buttons
Hide Buttons
Read previous post:
Android Kotlin Tutorial On BigDecimal || BigDecimal

Problem: Have you felt calculations a bit confused any time or making multiple calculations changing your result / output.You may...

Close