Kotlin program to get the List equivalent of the given Triple

Example of toList() function: Learn how to get the List equivalent of the given Triple?
Submitted by IncludeHelp, on April 09, 2022

Here, we will demonstrate the use of the toList() function with Triple in Kotlin. The toList() function returns the List equivalent of the given Triple.

Syntax:

fun <T>Triple<T, T, T>.toList(): List<T>

Example 1:

fun main() {
	// creating a new instance of the Triple
	var numbers = Triple(10, 20, 30)

	// Convert to the list using toList()
	val list1: List<Any> = numbers.toList()

	// Print the list
	println("List representation is "+list1.toString())	
}

Output:

List representation is [10, 20, 30]

Example 2:

fun main() {
	// creating a new instance of the Triple
	var student = Triple("Alvin Alexander", 35, "New York")

	// Convert to the list using toList()
	val list1: List<Any> = student.toList()

	// Print the list
	println("List representation is "+list1.toString())	
}

Output:

List representation is [Alvin Alexander, 35, New York]

Kotlin Triple Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.