Chapter 15 - 컬렉션 자료구조 확인문제

김태원·2023년 1월 10일
0

Chapter 15 - 컬렉션 자료구조 확인문제

정답: 4

Stack은 LIFO(후입선출) 자료구조를 구현한 클래스이다.

정답: 3

ArrayList에서 객체를 삭제하면 삭제된 객체 뒤에 있는 객체들이 한칸씩 앞으로 당겨진다.

정답: 4

Set 컬렉션에도 null을 저장할 수 있다. 단, 1개의 null만 저장할 수 있다.

정답: 3

멀티 스레드 환경에서는 HashMap 보다는 Hashtable이 스레드에 안전하다(Thread-safe).

정답:

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

정답:

Map<String, Integer> hashMap = new HashMap<>();


실행 결과

제목1-내용1
제목2-내용2
제목3-내용3

정답:

public class BoardDao {
    public List<Board> getBoardList() {
        List<Board> arrayList = new ArrayList<>();
        for (int i = 1; i < 4; i++) {
            arrayList.add(new Board("제목" + i, "내용" + i));
        }
        return arrayList;
    }
}


실행 결과

저장된 객체 수: 2
1:홍길동
2:신용권

정답:

@Override
public int hashCode() {
    return studentNum;
}

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof Student student)) return false;
    return studentNum != student.studentNum;
}

정답:

double averageScore; // 평균 점수를 저장하는 변수

for (Map.Entry<String, Integer> e : map.entrySet()) {
    int score = e.getValue();
    totalScore += score;

    if (e.getValue() > maxScore) {
        name = e.getKey();
        maxScore = score;
    }
}
averageScore = (double) totalScore / map.size();

System.out.printf("평균 점수: %.1f\n", averageScore);
System.out.println("최고 점수: " + maxScore);
System.out.println("최고 점수를 받은 아이디: " + name);


정답:

public class Student implements Comparable<Student>
@Override
public int compareTo(Student o) {
    return score == o.score ? 0 : (score < o.score ? -1 : 1);
}

정답: 4

Stack은 클래스가 맞지만 Queue는 클래스가 아닌 인터페이스이다.

정답: 3

Vector는 동기화된 컬렉션이 맞지만 HashMap은 동기화된 컬렉션이 아니다. Hashtable이 동기화된 컬렉션이다.

정답: 4

Array.asList() 메소드는 배열로부터 수정할 수 없는 List 컬렉션을 생성한다.

profile
개발이 재밌어서 하는 Junior Backend Developer

0개의 댓글