- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2041 Articles for Mobile Development
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
366 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
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
5K+ 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
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
147 Views
In this example, we will see how to print 0001 to 1000 in Kotlin with padding. For this purpose, we will use a Kotlin library function called padStart().padStart is a function which returns a charSequence. Its function definition looks like this −fun CharSequence.padStart( length: Int, padChar: Char = ' ' ): CharSequenceExample – Print 0001 to 1000 with paddingThe following code prints 1 to 1000 with padding.fun main(args: Array) { (1..1000).forEach{println("$it".padStart(4, '0'))} }OutputOn execution, it will print a sequence of 4-digit numbers starting from 0001 to 1000.0001 0002 0003 0004 ... ... ... 0996 0997 0998 0999 1000
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
515 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
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
1K+ Views
Kotlin is statistically typed language and it is hundred percent comparable with Java, as it was developed based on JVM. In Kotlin, there are two types of equality checks −One is denoted by "==" andThe other one is denoted by "===".As per the official documentation, "==" is used for structural equality, whereas "===" is used for referential equality.For any expression, a==b will evaluate to True only when the value of both "a" and "b" are equal.a===b will evaluate to True only when both "a" and "b" are pointing to the same object.Example – Equality in KotlinIn this example, we will ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
2K+ Views
In this article we will see how we can remove an item from an ArrayList using Kotlin library function. In order to do that, we will take the help of a library function called drop(). The function definition looks as follows −fun Array.drop(n: Int): List (source)It takes array and a position as an input and it returns a list containing all the elements except the first n elements.Example – drop() in KotlinIn this example, we will remove the first element from a list using drop().fun main(args: Array) { var arrayone: ArrayList = arrayListOf("mango", "jam", "apple", "lemon", "spice") ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
954 Views
A list is a collection to hold same type of data in a single variable. Kotlin does not provide any dedicated literal to create a collection. As per the documentation of Kotlin, a List is an ordered collection with access to elements by indices.In Kotlin, we do have two different kinds of collections; one is read-only which is known as immutable collection and the other type of collection is where we can have a write facility as well which is known as mutable collection.In this article, we will see how we can create these two types of lists and manipulate ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
314 Views
An array is a collection where we can store multiple items of the same type. We can consider an array of integers or an array of strings. This is very useful, for example, whenever we need to store the name of 1000 students in a single variable.Example – Using arrayOf()In this example, we will see how we can create an empty array in Kotlin. We will be creating an empty array of Strings and manipulate the same in the program.fun main(args: Array) { // Declareting empty array of type String val emptyStringArray = arrayOf() println("Example of empty ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
212 Views
In this article, we will take an example and demonstrate how we can obtain the class reference in Kotlin. Kotlin does not support fetching the class reference directly, but you can obtain the same reference via extension itself. In the following example, we will see how we can do it via Kotlin library functions.Example – Class reference using KClassIn this example, we will get the reference of the class.import kotlin.reflect.KClass fun main(args : Array) { // to get the reference of the class fun T.getClass(): KClass { return javaClass.kotlin } val ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
587 Views
In this article, we will take an example to demonstrate how we can extend and implement in the same class. In this example, We will be creating an interface and a dummy Parent class.From the Child class, we will extend the Parent class and implement the interface.Example – Extending and implementing in childinterface myInterface { fun test(): String } open class myParentClass(val name:String) { fun anotherTest():String { return name } } class Child() : myInterface, myParentClass("ParentClass Input"){ //child extending the parent class and implementing myInterface override fun test(): String { ... Read More