Implementation of HashMap in kotlin

HashMap I implemented HashMap with kotlin. id is key and name is value

maptest.kt



import java.util.Scanner
import java.util.InputMismatchException

var map = kotlin.collections.HashMap<Int , String>()

fun main(arg : Array<String>) {
    val input = Scanner(System.`in`)
    var i : Int
    try {
    loop@ while(true) {
            println("What are you doing?\n" +
                    "input=>1" + "display=>2" + "look for=>3" + "Delete=>4"+ "End=>5")
            i = input.nextInt()
            when (i) {
                1 -> {
                    Scan()
                }
                2 -> {
                    println(map)
                }
                3 -> {
                    search()
                }
                4 -> {
                    delete()
                }
                5->{
                    break@loop
                }
            }
    }
    }catch(e : InputMismatchException){
        println("The type is different: " +e)
    }
}

map.kt


import java.util.*
val input = Scanner(System.`in`)

fun search(){
    val key : Int
    println("Please enter id")
    try {
        key = input.nextInt()
        if (map.containsKey(key)) {
            println("$key =" + map.get(key))
        } else {
            println("That id does not exist")
        }
    }catch (e : InputMismatchException){
        println("The type is different: ")
    }
}
fun Scan(){
    println("Please enter your name")
    val name =  input.next()
    println("Please enter id")
    val key : Int = input.nextInt()
    try {
        if (map.containsKey(key)) {
            println("Do you want to overwrite?\n" +
                    "Yes=>1 No=>2")
            when (input.nextInt()) {
                1 -> {
                    map.put(key, name)
                }
                2 -> {
                }
            }
        } else {
            map.put(key, name)
        }
    }
    catch (e : InputMismatchException){
        println("The type is different: ")
    }
}
fun delete() {
    println("Delete all=>1 1 Delete data=>2 Cancel=>3")
    try {
        when (input.nextInt()) {
            1 -> {
                map.clear()
            }
            2 -> {
                println("Please enter the id to delete")
                val keyid: Int = input.nextInt()
                map.remove(keyid)
            }
            3 -> {
            }
        }
    }catch (e : InputMismatchException){
        println("The type is different: ")
    }
}


The implementation such as inputting the name in Japanese and retrying is coming again.

Recommended Posts

Implementation of HashMap in kotlin
Implementation of tri-tree in Java
Implementation of ls command in Ruby
Implementation of asynchronous processing in Tomcat
Implementation of like function in Java
Implementation of DBlayer in Java (RDB, MySQL)
HMAC in Kotlin
Implementation of multi-tenant asynchronous processing in Tomcat
Implementation of GKAccessPoint
Implementation of digit grouping in flea market apps
SKStoreReviewController implementation memo in Swift UI of iOS14
[Rails] Implementation of retweet function in SNS application
[Rails] Implementation of "notify notification in some way"
Interpreter implementation in Java
Implementation of flash messages
Implementation of search function
Boyer-Moore implementation in Java
Applied implementation of chat-space
Heapsort implementation (in java)
Implementation of pagination function
Output in multiples of 3
Initializing HashMap in Java
Implementation of asynchronous processing for single tenant in Tomcat
Browse class objects in Kotlin (instead of Java class name.class)
[Swift] Simple implementation of UIImageView
Implementation of sequential search function
[Swift] Implementation of ultra-simple billing
Implementation of like function (Ajax)
[Java] Implementation of Faistel Network
Implementation of XLPagerTabStrip with TabBarController
[Rails] Implementation of category function
Rails sorting function implementation (displayed in order of number of like)
[Java] Get KClass in Java [Kotlin]
Implementation of category pull-down function
Implementation of unit test code
[Rails] Implementation of tutorial function
Judgment of fractions in Ruby
[Rails] Implementation of like function
Apache POI Excel in Kotlin
Pitfalls of WebTarget.queryParam () in JAX-RS
Find the number of days in a month with Kotlin
[Rails] Implementation of new registration function in wizard format using devise
Let's create a TODO application in Java 4 Implementation of posting function
Let's create a TODO application in Java 6 Implementation of search function
Let's create a TODO application in Java 8 Implementation of editing function
Mechanism and characteristics of Collection implementation class often used in Java
[Rails] Implementation of user logic deletion
[Rails] Implementation of CSV import function
Basics of sending Gmail in Ruby
[rails] Login screen implementation in devise
Screen transition using Intent in Kotlin
[Rails] Implementation of image preview function
Easy implementation of Android file browsing
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
Differences in split methods of StringUtils
Implement Material Design View in Kotlin
Error handling in gRPC (Kotlin version)
Imitate Java's functional interface in Kotlin
Implementation of validation using regular expressions