首页javaconcurrentJava Thread - 如何从数据库读取字符串...

Java Thread - 如何从数据库读取字符串...

我们想知道如何从数据库读取字符串。...
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Main {
  public static Map<String, String> mapGetter() {
    return MapHolder.staticMap;
  }
  public static void main(String[] arg) {
    Map<String, String> m = mapGetter();
    System.out.println("we get it: " + m);
  }
}

class MapHolder {
  static final Map<String, String> staticMap;
  static {
    Map<String, String> tempMap = new HashMap<String, String>();

    tempMap.put("key 1", "value 1");
    tempMap.put("key 2", "value 2");
    tempMap.put("key 3", "value 3");

    staticMap = Collections.unmodifiableMap(tempMap);
  }
}