0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java_HashMapの基本操作

Posted at

paizaラーニングforTEAM Java入門編
レッスン9の#03

9-#03
// HashMapの基本操作
import java.util.HashMap;

public class Main {
    public static void main(String[] args) {
        HashMap<String, String> enemyMap = new HashMap<String, String>();
        enemyMap.put("ザコ", "スライム");
        enemyMap.put("中ボス", "ドラゴン");
        enemyMap.put("ラスボス", "魔王");
        
        // System.out.println(enemyMap.get("中ボス"));
        
        // HashMapのキーを変数で指定
        enemyMap.remove("中ボス"); // エントリーを削除
        String level = "中ボス";
        System.out.println(enemyMap.get(level));
        
        // level = "未定義";
        // System.out.println(enemyMap.get(level));
        System.out.println(enemyMap.size()); // エントリー数を調べる
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?