kotlin.collections.MapsJVM.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib Show documentation
Show all versions of kotlin-stdlib Show documentation
Kotlin Standard Library for JVM
package kotlin
import java.util.Comparator
import java.util.LinkedHashMap
import java.util.SortedMap
import java.util.TreeMap
import java.util.Properties
// Map APIs
/**
* Converts this [[Map]] to a [[LinkedHashMap]] so future insertion orders are maintained
*/
public fun Map.toLinkedMap(): LinkedHashMap = toMap(LinkedHashMap(size)) as LinkedHashMap
/**
* Converts this [[Map]] to a [[SortedMap]] so iteration order will be in key order
*
* @includeFunctionBody ../../test/collections/MapTest.kt toSortedMap
*/
public fun Map.toSortedMap(): SortedMap = toMap(TreeMap()) as SortedMap
/**
* Converts this [[Map]] to a [[SortedMap]] using the given *comparator* so that iteration order will be in the order
* defined by the comparator
*
* @includeFunctionBody ../../test/collections/MapTest.kt toSortedMapWithComparator
*/
public fun Map.toSortedMap(comparator: Comparator): SortedMap = toMap(TreeMap(comparator)) as SortedMap
/**
* Converts this [[Map]] to a [[Properties]] object
*
* @includeFunctionBody ../../test/collections/MapTest.kt toProperties
*/
public fun Map.toProperties(): Properties {
val answer = Properties()
for (e in this) {
answer.put(e.key, e.value)
}
return answer
}