假设现在我有   啊 阿 埃 挨 哎 唉 哀 皑 癌 蔼 矮 艾 碍 爱 隘   这写汉字,而这些汉字都是以拼音字母 a 开头的,我想要目的就是能不能先把这些字放入到内存中,然后很快的将其读取出来,最后达到的效果为:
System.out.print(xxx.get("啊"));输出的结果就为 a

解决方案 »

  1.   

    需要汉字拼音映射表(此map表网上可以找到)
    Map<String,String> map = new Hashmap<String,String>()
    map.put("啊","a");
    .....public String getPinYing(String hanzi)
    {
        return map.get(hanzi);
    }
      

  2.   

    如1L所说,把文件内容用map保存就可以了
      

  3.   

    要取数据效率快点 ,可以用HashTable
      

  4.   

    程序启动了map什么都在内存啊,要不放哪?
      

  5.   


    public class MapDemo { // key -> 汉字    value -> 拼音          根据汉字找拼音 用这个map
    Map<String , String> map1 = new Hashtable<String , String>();
    // key -> 拼音   value -> 汉字 根据拼音找汉字用这个map
    Map<String , List<String>> map2 = new Hashtable<String , List<String>>(); public void putMap1(String key , String value){
    map1.put(key, value);
    } public void putMap2(String key , String... values){
    if(map2.get(key) == null)
    map2.put(key, new Vector<String>() );
    for (String value : values)
    map2.get(key).add(value);
    }


    public void init(){
    //给map1添加数据
    putMap1("啊", "a");
    putMap1("你", "ni");
    putMap1("我", "wo");
    putMap1("他", "ta");

    //给map2添加数据
    putMap2("a", "啊");
    putMap2("a", "阿");
    putMap2("a", "吖");
    putMap2("e", "额");
    putMap2("e", "饿");
    putMap2("e", "の");
    putMap2("e", "俄");
    putMap2("ni", "你" , "拟" , "呢");
    }

    public static void main(String[] args) {
    MapDemo md = new MapDemo();
    md.init() ;
    System.out.println(md.map1.get("你"));
    System.out.println(md.map2.get("a"));
    System.out.println(md.map2.get("e"));
    System.out.println(md.map2.get("ni"));
    }

    }