Skip to content

Instantly share code, notes, and snippets.

@stefanJi
Last active May 17, 2019 02:43
Show Gist options
  • Save stefanJi/82430a3a821d2819c5b116d92c46c412 to your computer and use it in GitHub Desktop.
Save stefanJi/82430a3a821d2819c5b116d92c46c412 to your computer and use it in GitHub Desktop.
Kotlin 两个集合的差集
/**
* Returns a list of all the elements that are not included in this collection and that are not included in the specified collection.
*/
public fun <T> Iterable<T>.subtractX(other: Iterable<T>): List<T> {
return filterNot { other.contains(it) } + other.filterNot { contains(it) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment