1

How to output a random string from a given array of string or from a list in Kotlin

var arr = arrayOf("People", "Are", "Awesome")
1
  • You can make it even randomly Array like: var arr = arrayOf("People", "Are", "Awesome").random() then println(arr) Commented Aug 11, 2020 at 10:48

1 Answer 1

5

You can use the random function: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/random.html

fun main() {
  val arr = arrayOf("People", "Are", "Awesome")
  println(arr.random())
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.