ADVERTISEMENT
ADVERTISEMENT

Kotlin program to retrieve the values of Triple using properties

Learn how to create a Triple and access/retrieve its values using the properties?
Submitted by IncludeHelp, on April 06, 2022

In the previous example, we have discussed how to retrieve the Triple values using the variable name? There is another way which is using properties, with the help of some predefined properties we can easily get the Triple values.

Properties:

In Kotlin Triple, we can use the properties named "first", "second", and "third" to retrieve the values of Triple. The "first" property stores the first value of the Triple, the "second" property stores the second value, and the "third" property stores the third value.

Syntax:

pair_name.first
pair_name.second
pair_name.third

Example 1:

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

	// Printing the values
	println(numbers.first)
	println(numbers.second)
	println(numbers.third)
}

Output:

10
20
30

Example 2:

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

	// Printing the values
	println(student.first)
	println(student.second)
	println(student.third)
}

Output:

Alvin Alexander
35
New York

Kotlin Triple Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.