Remove duplicate word from sentence using LinkedHashSet in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" ")) | |
} |
Comments
Post a Comment