Skip to content

Instantly share code, notes, and snippets.

@zlandorf
Created July 4, 2020 16:16
Show Gist options
  • Select an option

  • Save zlandorf/07f368d849927e5b553c32fb27b80602 to your computer and use it in GitHub Desktop.

Select an option

Save zlandorf/07f368d849927e5b553c32fb27b80602 to your computer and use it in GitHub Desktop.
val treeSet = TreeSet<Int>()
val treeSetDescending = TreeSet<Int>(Collections.reverseOrder())
val hashSet = HashSet<Int>()
val random = Random()
repeat(10) {
val number = random.nextInt(100)
treeSet.add(number)
treeSetDescending.add(number)
hashSet.add(number)
}
println("sorted: $treeSet") // sorted: [5, 12, 31, 41, 56, 58, 76, 84, 89, 98]
println("sorted descending: $treeSetDescending") // sorted descending: [98, 89, 84, 76, 58, 56, 41, 31, 12, 5]
println("not sorted: $hashSet") // not sorted: [98, 84, 5, 56, 89, 41, 58, 12, 76, 31]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment