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 @Baadshah이 값을 얻었으므로 잘 작동한다고 생각합니다. 고마워 durron597 :) – tmq
@tmq 녹색 체크 표시를 클릭하는 것을 잊지 마세요 :) – durron597
@ tmq 그 이유는 내가 +1 durron 준 –