Mobile Development Articles

Page 22 of 156

IntArray vs. Array in Kotlin

Soumak De
Soumak De
Updated on 16-Mar-2022 8K+ Views

In this article, we will take an example to show the difference between IntArray and Arrayin Kotlin.IntArray in KotlinIntArray is a class in Kotlin representing the array of elements. Each instance of this class is represented as an integer array. To the constructor of this class you need to pass the number of elements you need in the array (size).You can instantiate this class as shown below −val myArray = IntArray(8)By default, all the elements of the created array will be initialized to "0".ExampleThe following program creates an array of integers by instantiating the IntArray class −fun main(args: Array) { ...

Read More

What does the "===" operator do in Kotlin?

Soumak De
Soumak De
Updated on 16-Mar-2022 519 Views

In Kotlin, the "===" operator checks the referential equality of two objects. Any expression "a===b" will evaluate to True if and only if both "a" and "b" point to the same object. That is, both "a" and "b" share the same address.In contrast, we can use the "==" operator to check structural equality which implies that two objects have equivalent content. Basically, "==" is a check for equals().Example: "===" Operator in Kotlinfun main(args: Array) {    var str1 : String = "That's it"    var str2 : String = "It's OK"    var str3 : String = str1   ...

Read More

5G Networks and IoT

Kanal S Sajan
Kanal S Sajan
Updated on 16-Mar-2022 858 Views

The fourth industrial revolution is influencing every element of existence. New technologies emerge at a rapid pace. 5G networks and the Internet of Things (IoT) are two buzzwords in today's society that are becoming increasingly frequently used. You've probably seen them referenced on social media. So, what exactly is 5G? What is the Internet of Things (IoT)? What do these have in common, and what are their consequences? Let's take a closer look at 5G networks and IoT with Speranza today.What is the Internet of Things?The Internet of Things is a network of physical devices that are connected via the ...

Read More

How to print all the elements of a String array in Kotlin in a single line?

Soumak De
Soumak De
Updated on 01-Mar-2022 740 Views

In this article, we will take an example and show how to print all the elements of a String array in a single line using a Kotlin library class. In order to do that, we will use a String function called joinToString(), provided by the Kotlin library.As per the Kotlin documentation, the function definition looks like this −fun Array.joinToString(    // the String will be separated by this    separator: CharSequence = ", ",    // This will be added as prefix to the String    prefix: CharSequence = "",    // This will be added as postfix ...

Read More

How to add an item to a list in Kotlin?

Soumak De
Soumak De
Updated on 01-Mar-2022 932 Views

A List is a collection where you can store same type of data in one place. There are two types of lists in Kotlin −An Immutable list is something that cannot be modified. It is read-only in nature.The other type of list is mutable which can be modified.In this article, we will see how to create a mutable list and how to add an item to the existing list.Example – Adding an Item to a Mutable ListIn order to add an item to a list, we will be using add() that is provided by the Kotlin library class.fun main(args: Array) ...

Read More

How to get the current local date and time in Kotlin?

Soumak De
Soumak De
Updated on 01-Mar-2022 4K+ Views

Kotlin is a statistically typed language and it is based on Java, hence all the Java codes can easily be compiled within Kotlin. In this article, we will see how we can generate the current local date and time in Kotlin.As Kotlin is interoperable with Java, we will be using the Java utility class and Simple Date Format class in order to get the current local date and time.Example – Current Date and time using SimpleDateFormatimport java.text.SimpleDateFormat import java.util.* fun main(args: Array) {    val simpleDate = SimpleDateFormat("dd/M/yyyy hh:mm:ss")    val currentDate = simpleDate.format(Date())    println(" Current Date is: ...

Read More

How to convert Int to Hex String in Kotlin?

Soumak De
Soumak De
Updated on 01-Mar-2022 1K+ Views

Kotlin is statistically typed language and it is built on JVM. Kotlin is cent percent comparable with Java. Hence, some of the Java functions can be used in Kotlin as well.In this article, we will take an example to demonstrate how we can use a Java class function convert an Int in Kotlin to its correponding Hex String.Example – Converting Int to Hex String in KotlinIn this example, we will use the Java class function toHexString().import java.lang.* fun main(args: Array) {    val hexString = java.lang.Integer.toHexString(-66)    println("Hex String for negative Number: " +hexString)    val positiveNumber ...

Read More

Kotlin 'when' statement vs Java 'switch'

Soumak De
Soumak De
Updated on 01-Mar-2022 953 Views

Switch-case statement in any programming language allows the programmers to testify it against different values. It also provides an option to do something whenever the value of the variable does not match with a given value. In this article, we will take a simple example and demonstrate how we can implement the switch-case statement in Kotlin.Kotlin does not provide any option to write a switch-case statement. However, Kotlin provides an option to implement when() which works exactly the same way switch works in other programming languages.Example – Implementing switch-case in JavaIn this example, we will implement switch-case in Java.public class ...

Read More

How to reverse a Map in Kotlin?

Soumak De
Soumak De
Updated on 01-Mar-2022 627 Views

Kotlin provides four types of constructors to define and manipulate a HashMap. In this article, we will see how we can reverse a map using Kotlin library function.A Map is a collection where data is stored as a key-value pair and the corresponding key has to be unique.A HashMap is a collection class based on MutableMap interface and it does that by implementing the MutableMap interface of HashTable.Example − Reverse using Iterable associate()In this example, we will create a HashMmap and we will reverse the same using associate(). In this method, we will be creating a new map and we ...

Read More

How to convert TimeStamp to DateTime in Kotlin?

Soumak De
Soumak De
Updated on 01-Mar-2022 6K+ Views

Kotlin is a statistically typed language and it is based on Java, hence all the Java code can easily be compiled within Kotlin code. In this article, we will see how we can generate the current local date and time in Kotlin.As Kotlin is interoperable with Java, we will be using Java utility class and Simple Date Format class in order to convert TimeStamp into DateTime.Example – Converting DateTime using Java util classAs Kotlin is comparable with the JVM, we can use the Java util class in order to convert the TimeStamp into DateTime.import java.text.SimpleDateFormat import java.util.* fun main(args: ...

Read More
Showing 211–220 of 1,551 articles
« Prev 1 20 21 22 23 24 156 Next »
Advertisements