1. 4번 Stack은 LIFO Queue는 FIFO
2. 3번 중간에 값을 삭제하면 리스트 인덱스 재조정이 들어가고 크기도 바뀐다.
3. 4번 set에 null을 하나만 저장하는게 허용된다. 다만 TreeSet은 허용안한다. TreeMap을 내부적으로 이용하기 때문이다.
4. 3번 Hashtable 구시대 클래스이긴해도 멀티 스레딩은 보장된다.
5. ArrayDeque<Board> b = new ArrayDeque<>();
6. HashMap<String, Integer> h = new HashMap<>();
7.
public class BoardDao{
private ArrayList<Board> bl;
public BoarDao(){
bl = new ArrayList<>();
for(int i=1; i<=3; i++){
bl.add(new Board("제목"+i, "내용"+i));
}
}
public ArrayList<Board> getBoardList(){
return bl;
}
}
8.
public int hashCode(){
return studentNum;
}
public boolean equals(Student s){
if(this.hashCode == s.hashCode){
return true;
}else if(this.studentNum == s.studentNum){
return true;
}else{
return false;
}
}
9. 못풀음... 리스트 없이 어떻게 정렬한다는거진지 출제자 의도를 모르겠네요..
-> 답지: entrySet() 매서드를 이용해 Set을 만들고 순차 탐색하며 최대값 최대키 리셋 토탈값 누적
10.와 이것도 뭔말이지? TreeSet의 Last()결과가 최대 값인지 이걸 어떻게 Student 클래스에서 보장하는데..
-> TreeSet은 항상 Comparable 또는 Comaparator를 이용하여 내부 정렬을 시도한다. 자기 객체와 인자를 비교하는 연산은 Comparable임 Comaparable을 상속받아 compareTo를 구현하면 됨. 그리고 착각한게 있었네 TreeSet.last()는 그냥 정렬 기준 맨 오른쪽 가장 최대 값을 뽑아내는거임. 나는 루트 노드를 뽑아낸다고 착각했음.
11.4번 큐는 인터페이스임
12. 3번 HashMap은 동기화 안되어 있음
13. 4번 asList는 수정할 수 없는 리스트 컬렉션 생성임
9번 다시 풀이
Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
for(Map.Entry<String, Integer> e : entrySet){
if(e.getValue() > maxScore){
maxScore = e.getValue();
name = e.getKey();
}
totalScore += e.getValue();
}
System.out.println("평균 점수: " + totalScore/map.size());
System.out.println("최고 점수: " + maxScore);
System.out.println("최고 점수를 받은 아이디: " + name);
10번 다시 풀이
public class Student implements Comparable<Student>{
public String id;
public int score;
public Student(String id, int score){
this.id = id;
this.score = score;
}
public int compareTo(Student s){
if(this.score < s.score) return -1;
else if(this.score == s.score) return 0;
else return 1;
}
}
'Learn > 이것이 자바다' 카테고리의 다른 글
[이것이 자바다 확인문제] chapter 16 (0) | 2024.12.11 |
---|---|
람다식, 함수형 프로그래밍, 메소드 참조, 생성자 참조 (1) | 2024.12.11 |
컬렉션, List, Set, Map, 검색, Stack,Queue, Synchronizaton, immodified (1) | 2024.12.10 |
[이것이 자바다] chapter 13 확인문제 (0) | 2024.12.04 |
제네릭, 와일드카드 (0) | 2024.12.03 |