배열의 요소를 인쇄하기 위해 다른 클래스에서 toString 메서드에 액세스하려고합니다.arraylist의 요소를 표시
info += "Purchases:\n";
for(int index = 0; index < purchases.size(); index++){
info += "[" + (index + 1) + "] ";
info += purchases.get(index).toString();
info += "\n";
}
나는이 작업을 수행 할 수있는 방법
public String toString(){
String info;
DecimalFormat formatter = new DecimalFormat("$#0.00");
info= (date.get(Calendar.MONTH) +1) + "/" + date.get(Calendar.DAY_OF_MONTH) + "/" + date.get(Calendar.YEAR);
info += "\t" + vendor + "\t\t";
info += (formatter.format(amount));
return info;
}
를 인쇄하기 위해 구입 클래스에 있으며, toString에 액세스하는 코드를 싶습니다
?
을해야
: 루프 향상된에 사용 해보세요? – Aleadam