Kotlin Tutorial
Kotlin Useful Resources
Selected Reading
- Kotlin - Exception Handling
- Kotlin - Destructuring Declarations
- Kotlin - Delegation
- Kotlin - Generics
- Kotlin - Sealed Class
- Kotlin - Data Classes
- Kotlin - Extension
- Kotlin - Visibility Control
- Kotlin - Interface
- Kotlin - Abstract Classes
- Kotlin - Inheritance
- Kotlin - Constructors
- Kotlin - Class and Objects
- Kotlin - Maps
- Kotlin - Sets
- Kotlin - Lists
- Kotlin - Collections
- Kotlin - Break and Continue
- Kotlin - While Loop
- Kotlin - For Loop
- Kotlin - When Expression
- Kotlin - if...Else Expression
- Kotlin - Control Flow
- Kotlin - Functions
- Kotlin - Ranges
- Kotlin - Arrays
- Kotlin - Strings
- Kotlin - Booleans
- Kotlin - Operators
- Kotlin - Data Types
- Kotlin - Variables
- Kotlin - Keywords
- Kotlin - Comments
- Kotlin - Basic Syntax
- Kotlin - Architecture
- Kotlin - Environment Setup
- Kotlin - Overview
- Kotlin - Home
Kotlin Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Kotlin - Destructuring Declarations
Kotpn - Destructuring Declarations
Kotpn contains many features of other programming languages. It allows you to declare multiple variables at once. This technique is called Destructuring declaration.
Following is the basic syntax of the destructuring declaration.
val (name, age) = person
In the above syntax, we have created an object and defined all of them together in a single statement. Later, we can use them as follows.
println(name) println(age)
Now, let us see how we can use the same in our real-pfe apppcation. Consider the following example where we are creating one Student class with some attributes and later we will be using them to print the object values.
fun main(args: Array<String>) { val s = Student("TutorialsPoint.com","Kotpn") val (name,subject) = s println("You are learning "+subject+" from "+name) } data class Student( val a :String,val b: String ){ var name:String = a var subject:String = b }
The above piece of code will yield the following output in the browser.
You are learning Kotpn from TutorialsPoint.comAdvertisements