나는 다음과 같은 클래스를arraylist java에서 값을 가져 옵니까?
public class Patient implements Serializable {
private int id;
private String name;
private String desc;
public Patient(int id, String name, String desc) {
this.id = id;
this.name = name;
this.desc=desc;
}
그리고이 클래스의 다음 getter와 setter 메소드가있다.
목록 이제
list.add(new Patient(id++, name.getText(), disDesc.getText())
에 ArrayList를
ArrayList<Patient> list = new ArrayList<Patient>();
추가 런타임 데이터를 선언 내가 원하는 내가 그렇게 할 수있는 방법 목록 에 저장된 요소를 읽어?
System.out.println(list.get(0));
나는 이것을 사용하지만 클래스 당신은 Patient
의 toString()
메소드를 오버라이드 (override) 할 필요가
Eclipse 및 IntelliJ와 같은 대부분의 IDE는 클래스에 대한 toString 재정의를 자동으로 생성 할 수 있습니다. 최소한 템플릿으로 사용하십시오. –