public class Point {주요 클래스:
private int x;
private int y;
public Point(int x, int y){
this.x=x;
this.y=y;
}
@Override
public String toString() {
return "[x= "+this.x+", y= "+this.y+"]";
}
}
import java.util.ArrayList;실행:
public class Main {
public static void main(String[] args) {
ArrayList< 안건> 목록 = 새로운 ArrayList< 안건> ()
{
private static final long serialVersionUID = 1L;
@Override
public String toString()
{
return super.toString();
}
};
list.add(새 Point(2, 4));
list.add(새 포인트(1, 6));
list.add(새 Point(5, 2));
list.add(새 포인트(3, 7));
list.add(새 포인트(8, 9));
System.out.println(list.toString());
}
}
[[x= 2, y= 4], [x= 1, y= 6], [x= 5, y= 2], [x= 3, y= 7], [x= 8, y= 9]]이 예제에서 ArrayList는 메서드 toString() Point 클래스에 선언되어 있습니다. 메서드를 제거하면 toString() Point 클래스에서는
[Point@4a5f634c, Point@3c7038b9, Point@6b9c18ae, Point@55187eb3, Point@3b26456a]
Please disable your ad blocker and refresh the window to use this website.