Traversing Through/Printing out a Binary Tree Map in Java

So I have this Binary Tree Map (called "mainMap") that holds strings as its keys and each key has an inner map as its value pair. This map within a map holds string keys and integer values.

The purpose of this mainMap is to tell which word corresponds to which file and its frequency. e.g.: If "cat" is in "Arnold.txt" 14 times and it is in "Jake.txt" 6 times, the map will hold

key .... cat value ... Map [key ... Arnold.txt, value ... 14], [key .... Jake.txt, value ... 6]

This is no problem. My problem is TRAVERSING THROUGH AND PRINTING OUT the map. I want to

--For each key in the map 1) Visit the current key within the map 2) Print out that key 3) Retrieve the value (map) .........For each key in the value map .............a) Print out the key .............b) Print out the value 4) Skip a line, go to the next key, repeat steps 1-4

I was thinking I could use an iterator. However, much to my embarrassment, I have no clue how to go about the syntax with my code. (I am not using java's built in TreeMap utilities. I am using a programmer constructed data structure.

I have the following method within the Binary Tree Map code

public Iterator< KeyValuePair<K, E> > iterator()
    Iterator< KeyValuePair<K, E> > itr = new MyTreeItr();
    return itr;

public Iterator< KeyValuePair<K, E> > breadthFirstIterator()
   Iterator< KeyValuePair<K, E> > itr = new MyBreadthFirstItr();
   return itr;

I hope this is enough information. This print out is for testing purposes to make sure my map is collecting the data correctly.


I'm not sure how your tree is structured, but based on how you've described your data structure (Map<String, Map<String, Integer>>), you can try this:

public void printAll(Map<String, Map<String, Integer>> map){
    for(Map.Entry<String, Map<String,Integer>> entry : map.entrySet()){
        for( Map.Entry<String, Integer> innerEntry : entry.getValue().entrySet()){

Need Your Help

Eclipse, Tomcat 7 NoClassDefFoundError

java tomcat7

Trying to run a program in Eclipse on Tomcat 7.0.12 and I'm getting this error: