I have 2 classes.
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();
}
}
and 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;
}
}
Output always looks like "Row@da52a1" or similar. How to fix that? I want to be able to do something like this with easy access to each of strings:
str="string1","string2","string3"; // it's kind of pseudocode ;)
rows.put(1,str);
rows.get(1);
As you can see, I've created class Row to use its as object of Map, but I have no idea what is wrong with my code.