「Java」Hashtableクラスを使うサンプル
書式
new Hashtable<String, Integer>()
public V get(Object key)
指定されたキーがマップされている値を返します。
使用例
package com.arkgame.study;
import java.util.Hashtable;
public class HashTableDemo {
static Hashtable<String, Integer> cb = new Hashtable<String, Integer>();
public static void main(String[] args) {
cb.put("first", new Integer(110));
cb.put("second", new Integer(250));
cb.put("three", new Integer(360));
find("second");
}
public static void find(String str) {
Integer n = (Integer) cb.get("second");
if (n != null) {
System.out.println("second = " + n);
}
}
}
実行結果
second = 250