「java」 java.util.Map.containsKey()、put(),remove(),size(),clear()の使い方

Javaコード
package itstudy;
import java.util.HashMap;
import java.util.Map;

public class JavaTestDemo {

public static void main(String[] args) {
Map<String, String> cft = new HashMap<String, String>();

setKVFunc(cft);

System.out.println(cft.get(“4")); // key=4の値を取り出す
System.out.println(cft.containsKey(“4"));
System.out.println(“Hascftap: " + cft);
System.out.println(“Hascftap size: " + cft.size());

cft.remove(“4"); // key=4を削除する
System.out.println(cft.containsKey(“4"));
System.out.println(“Hascftap: " + cft);
System.out.println(“Hascftap size: " + cft.size());

System.out.println(cft.remove(“1"));
System.out.println(cft.remove(“9999"));
}

static private void setKVFunc(Map<String,String> m){

m.put(“2", “81");
m.put(“3", “62");
m.put(“1", “76");
m.put(“5", “tokyo");
m.put(“6", “oosaka");
m.put(“4", “fukuoka");
}

}
実行結果
fukuoka
true
Hascftap: {1=76, 2=81, 3=62, 4=fukuoka, 5=tokyo, 6=oosaka}
Hascftap size: 6
false
Hascftap: {1=76, 2=81, 3=62, 5=tokyo, 6=oosaka}
Hascftap size: 5
76
null

Java

Posted by arkgame