Remove duplicate word from sentence using LinkedHashSet in Kotlin

fun main(args: Array<String>) {
/* Remove Duplicate words
* from Sentence using
* LinkedHashSet*/
val sentence = "Hi Guys Hi Android" +
" Hello Android Hi Kotlin"
val words = sentence.split(
"\\s+".toRegex()
)
val uniqueList = LinkedHashSet<String>(
words
)
println(uniqueList.joinToString(" "))
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments

Popular posts from this blog

Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.2.1. Cannot sync the project.

Google Assistant Implementation in Android application with app actions