A A A B A T C A B *B* From the root, search for B*. B does match BAT, so starting from B I'll search for *. From B, I search for "" I don't find "" since my B is not at the end of string. And from A I search for *. From A I search for "". I don't find "" since A is not at the end of the string. From T I search for *. From T I search for "". T is the end-of-string, so I found it, BAT gets printed. From all of my children, search for *B*. From A, search for *B* From (the first) A, I search for B* This fails, since I have no B child. From (the second) A, I search for *B* From (the second) A, I search for B*. This fails, since this A has no B child. From (the third) A, I search for *B*. From (the third) A, I search for B*. This fails, since this has no B child. From C I search for B* This one fails, since C has no B child. From A I search for *B*. From A I search for B*. Since I have a B child, from B I search for *. From B, I search for "". Since B has an end-of-string marker, I find "" I print "CAB". From B I search for *B*. From B, I search for B*. B has no B child, so this search fails. In Java, int is not a class, and so you can't use them in HashMaps BUT... Integer IS totally a class. Integer is a wrapper class for int.