Q:

Kotlin program to get the string equivalent of the Triple

0

Here, we will demonstrate the use of the toString() function with Triple in Kotlin. The toString() function returns the string equivalent of the Triple.

Syntax:

fun toString(): String

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Example 1:

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

	// Printing the Triple in string format
	println("String representation is "+numbers.toString())	
}

Output:

String representation is (10, 20, 30)

Example 2:

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

	// Printing Triple in string format
	println("String representation is "+student.toString())	
}

Output:

String representation is (Alvin Alexander, 35, New York)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now