我有2个班。如何打印出HashMap值?输出像xxx @ da52a1
Main.java
import java.util.HashMap;
import java.util.Map;
public class Main {
Map<Integer, Row> rows = new HashMap<Integer, Row>();
private Row col;
public Main() {
col = new Row();
show();
}
public void show() {
// col.setCol("one", "two", "three");
// System.out.println(col.getCol());
Row p = new Row("raz", "dwa", "trzy");
Row pos = rows.put(1, p);
System.out.println(rows.get(1));
}
public String toString() {
return "AA: " + rows;
}
public static void main(String[] args) {
new Main();
}
}
和Row.java
public class Row {
private String col1;
private String col2;
private String col3;
public Row() {
col1 = "";
col2 = "";
col3 = "";
}
public Row(String col1, String col2, String col3) {
this.col1 = col1;
this.col2 = col2;
this.col3 = col3;
}
public void setCol(String col1, String col2, String col3) {
this.col1 = col1;
this.col2 = col2;
this.col3 = col3;
}
public String getCol() {
return col1 + " " + col2 + " " + col3;
}
}
输出总是看起来像 “行@ da52a1” 或类似。如何解决这个问题?我希望能够做这样的事,方便前往各字符串:
str="string1","string2","string3"; // it's kind of pseudocode ;)
rows.put(1,str);
rows.get(1);
正如你所看到的,我创建的类行利用其作为地图的对象,但我不知道是什么我的代码有问题。
@Baadshah我有这个值,所以我认为它运作良好。谢谢durron597 :) – tmq 2013-04-26 14:02:10
@tmq没问题,不要忘了点击绿色的复选标记:) – durron597 2013-04-26 14:02:56
@tmq这就是我给durron +1的原因:) – 2013-04-26 14:05:37