Horje
find max key value in map in kotlin Code Example
find the greatest number in hashmap
public class NewClass4 {
    public static void main(String[] args)
    {
        HashMap<Integer,Integer>map=new HashMap<Integer, Integer>();
        map.put(1, 50);
        map.put(2, 60);
        map.put(3, 30);
        map.put(4, 60);
        map.put(5, 60);
        int maxValueInMap=(Collections.max(map.values()));  // This will return max value in the Hashmap
        for (Entry<Integer, Integer> entry : map.entrySet()) {  // Itrate through hashmap
            if (entry.getValue()==maxValueInMap) {
                System.out.println(entry.getKey());     // Print the key with max value
            }
        }

    }
}
find max key value in map in kotlin
fun max(map:Map<Int,String>) =  map.maxByOrNull { it.key }?.key ?:-1//returns negative one if the max is null
fun main(){
var map = mapOf(1 to "hello",2 to "peace", 3 to "ochuko")
    println(map.maxByOrNull { it.key }?.key ?:-1)
}
find max key value in map in kotlin
//For kotlin
fun max(map:Map<Int,String>) =  map.maxByOrNull { it.key }?.key ?:-1//returns negative one if the max is null
fun main(){
var map = mapOf(1 to "hello",2 to "peace", 3 to "ochuko")
    println(map.maxByOrNull { it.key }?.key ?:-1)
}




Java

Related
Rotate array to left k cells python Code Example Rotate array to left k cells python Code Example
worldedit api paste schematic Code Example worldedit api paste schematic Code Example
tree height recursion Code Example tree height recursion Code Example
functionality of consumer functional interface in java Code Example functionality of consumer functional interface in java Code Example
maven show runtime classpath Code Example maven show runtime classpath Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8