如何遍历树形图java中的树形图

时间:2016-04-12 16:01:04

标签: java iteration treemap

你好,我有这个树图:

 public static class Info {

  int totalOccurrences;
  int maxTF ; 
  ArrayList<Node> pointer;
  //ArrayList<String> files;  // document frequency --> files.size()
  TreeMap<String, Integer> files;

  Info(String selected) {

       totalOccurrences = 0;

       pointer = new ArrayList<Node>();
       pointer.add(new Node(selected));

       //files = new ArrayList<String>();
       files = new TreeMap();

       maxTF = 0 ; 
  }

 }

类信息和节点是这样的:

{{1}}

所以我想要做的是获取每个文件TreeMap的整数值 其中一个单词Treemap元素

换句话说,如何在TreeMap中迭代TreeMap?

非常感谢

1 个答案:

答案 0 :(得分:-1)

这应该有效:

TreeMap<String, Info> words = new TreeMap();

public static class Info {

    int totalOccurrences;
    int maxTF;
    ArrayList<Node> pointer;
    //ArrayList<String> files;  // document frequency --> files.size()
    TreeMap<String, Integer> files;

    Info(String selected) {

        totalOccurrences = 0;

        pointer = new ArrayList<Node>();
        pointer.add(new Node(selected));

        //files = new ArrayList<String>();
        files = new TreeMap();

        maxTF = 0;
    }

}

public void test() {
    // For each Info in the `words`
    for (Info i : words.values()) {
        // For each file in `files`
        for (Map.Entry<String, Integer> e : i.files.entrySet()) {
            System.out.println("i=" + i + " e=" + e);
        }
    }
}