fun main(args: Array<String>) { val ipToCount = mutableMapOf<String, Int>() File("src/ips.txt").forEachLine { val previous = ipToCount.getOrDefault(it, 0) ipToCount.put(it, previous + 1) } // get max count ip val (maxIp, maxCount) = ipToCount.entries.maxBy { it.value }!! }