2012-03-16 55 views
1

仅供参考,我在学校为作业创建了霍夫曼树。我已经创建了树,并存储使用该格式在图值:如果我有钥匙,我如何从地图中获得价值?

map.put((char,string)); 

炭:通过在从一个缓冲读取器 串一次读取一个字符导出:是分配给该“二进制”代码字符基于它的树的位置

现在我想产生一个“二进制”的字符串,表示我的缓冲读取器的初始输入。我该怎么做呢?这是我试过的:

String binary = ""; 
int q;  
while ((q = buffer.read()) != -1) { 
    char key = (char)q; 
    char value = (char)key.get(); 
    binary += value; 
} 
System.out.println(binary); 
+0

什么是地图的声明? – 2012-03-16 03:56:04

回答

3

不应该只是value = map.get(key)?

+0

谢谢。我知道我错过了一些简单的事情。我应该睡一会儿。 – Justin 2012-03-16 03:55:59

+0

:) ............. – dbrin 2012-03-16 03:58:49

1

这是我做,如果我想获得的所有键和值从地图:

Set <generics> mySet = myMap.keySet(); // takes all the keys to a set 
Iterator itr = mySet.iterator(); // setting iterator to the set containing the keys 

//iterate through the set of keys 

while (itr.hasNext()){ 

       keys = itr.next(); //get the keys from the set 
       values = myMap.get (keys); //get the values from the map 

}//while (itr.hasNext())