App下載
首頁javaconcurrentJava Thread - 如何從數(shù)據(jù)庫讀取字符串...

Java Thread - 如何從數(shù)據(jù)庫讀取字符串...

我們想知道如何從數(shù)據(jù)庫讀取字符串。...
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);
  }
}