我有三個嵌套樹映射的類。我有一個方法來在每個映射中放入值以及一種方法來檢索這些值。我的問題是,與其檢索值在控制檯輸出是這樣的:[email protected]
樹圖檢索HashMap的值而不是樹映射值Java
我怎麼輸入值:
Verbal square = new Verbal();
square.addVerbal("arbol1", square.addInVerbal("arbol2", square.addInInVerbal("atributo name", "attributeValue")));
如何檢索值:
System.out.println(square.getVerbal("arbol1").getInVerbal("arbol2").getInInVerbal("atributo name"));
父圖:
import java.util.TreeMap;
public class Verbal extends InVerbal {
private TreeMap<String, InVerbal> squareRPM = new TreeMap<String, InVerbal>();
public TreeMap<String, InVerbal> getSquareRPM() {
return squareRPM;
}
public void setSquareRPM(TreeMap<String, InVerbal> squareRPM) {
this.squareRPM = squareRPM;
}
//Put items in the treemap
public Verbal addVerbal(String key, InVerbal component){
squareRPM.put(key, component);
return this;
}
//Get items in the treemap
public Verbal getVerbal(String key){
squareRPM.get(key);
return this;
}
}
父內部的地圖
import java.util.TreeMap;
public class InVerbal extends InInVerbal {
private TreeMap<String, InInVerbal> component = new TreeMap<String, InInVerbal>();
public TreeMap<String, InInVerbal> getComponent() {
return component;
}
public void setComponent(TreeMap<String, InInVerbal> component) {
this.component = component;
}
//Put items in the treemap
public InVerbal addInVerbal(String key, InInVerbal attributes){
component.put(key, attributes);
return this;
}
//Get items in the treemap
public InVerbal getInVerbal(String key){
component.get(key);
return this;
}
}
內蒙古地圖>內部內地圖>裏面父
import java.util.TreeMap;
public class InInVerbal {
private TreeMap<String, String> attribute = new TreeMap<String, String>();
public TreeMap<String, String> getAttribute() {
return attribute;
}
public void setAttribute(TreeMap<String, String> attribute) {
this.attribute = attribute;
}
//Put items in the treemap
public InInVerbal addInInVerbal(String attributeName, String attributeValue){
attribute.put(attributeName, attributeValue);
return this;
}
//Get items in the treemap
public InInVerbal getInInVerbal(String attributeName){
attribute.get(attributeName);
return this;
}
}
預先感謝您。
謝謝@sharonbn提供反饋。添加該方法會在控制檯中給出「線程中的異常」主「java.lang.StackOverflowError」錯誤輸出。 –
我想這是B/C樹形圖包含Verbal的實例,其中包含含有Verbal實例的樹圖,其中包含....嘗試在其他類(InVerbal和InInVerbal)中實現不同的toString()在地圖上打印第一個項目(或者做一些很好的舊調試) –