231221 JAVA List02

2023. 12. 26. 18:482023.11.21-2024.05.31

package coll;

 

import java.util.ArrayList;

import java.util.List;

 

class Board {//데이터 전송 객체 =DTO

private int no, like;

private String title, write, date;

 

public Board(int no, String title, String write, String date, int like) {

this.no = no;

this.title = title;

this.write = write;

this.date = date;

this.like = like;

 

}

//getter /setter

 

public int getNo() {

return no;

}

 

public void setNo(int no) {

this.no = no;

}

 

public int getLike() {

return like;

}

 

public void setLike(int like) {

this.like = like;

}

 

public String getTitle() {

return title;

}

 

public void setTitle(String title) {

this.title = title;

}

 

public String getWrite() {

return write;

}

 

public void setWrite(String write) {

this.write = write;

}

 

public String getDate() {

return date;

}

 

public void setDate(String date) {

this.date = date;

}

 

}

 

public class List03 {

public static void main(String[] args) {

 

List<Board> list = new ArrayList<Board>();

Board board = new Board(1, "첫번째 글", "poseidon", "2023-12-01", 1);

list.add(board);

Board board2 = new Board(2, "두번째 글", "홍길동", "2023-12-11", 10);

list.add(board2);

Board board3 = new Board(3, "세번째 글", "최길동", "2023-12-13", 15);

list.add(board3);

Board board4 = new Board(4, "네번째 글", "정길동", "2023-12-12", 19);

list.add(board4);

Board board5 = new Board(5, "다섯번째 글", "황길동", "2023-12-14", 8);

list.add(board5);

 

System.out.println(list);

 

for (int i = 0; i < list.size(); i++) {

System.out.print(list.get(i).getNo() + "\t");

System.out.print(list.get(i).getTitle() + "\t");

System.out.print(list.get(i).getWrite() + "\t");

System.out.print(list.get(i).getDate() + "\t");

System.out.println(list.get(i).getLike() + "\n");

 

}

 

}

}

 

 

[coll.Board@73a28541, coll.Board@6f75e721, coll.Board@69222c14, coll.Board@606d8acf, coll.Board@782830e]

1 첫번째 글 poseidon 2023-12-01 1

 

2 두번째 글 홍길동 2023-12-11 10

 

3 세번째 글 최길동 2023-12-13 15

 

4 네번째 글 정길동 2023-12-12 19

 

5 다섯번째 글 황길동 2023-12-14 8

 

'2023.11.21-2024.05.31' 카테고리의 다른 글

231221 JAVA Set  (0) 2023.12.26
231221 JAVA Map01  (1) 2023.12.26
231221 JAVA List01  (0) 2023.12.26
231221 JAVA coll01  (0) 2023.12.26
231221 JAVA Study(오늘 할 것/앞으로 할 것)  (1) 2023.12.21