Skip to content

Conversation

@JAEKWANG97
Copy link
Member

@JAEKWANG97 JAEKWANG97 commented May 19, 2024

ArrayList

📝 구현하면서 어려웠던 점

  • remove를 하면서 어떤 방식으로 구현해야 할지 고민했습니다. System.arraycopy() 메서드를 활용해서 구현했습니다.
  • SuppressWarnings 어노테이션 사용 (E 타입으로 캐스팅할 때 발생할 수 있는 경고를 억제)
  • 제네릭 사용이 익숙치 않아 어려웠습니다. IDE 도움을 받았습니다.

💬 리뷰 요구사항(선택)

리뷰어에게 궁금한 내용을 작성해주세요

@JAEKWANG97 JAEKWANG97 changed the title [ArrayList]: isEmpty, get, insert, remove, size, grow, contains ArrayList/JAEKWANG97 May 19, 2024
@github-actions
Copy link

Unit Test Results

6 tests   6 ✔️  0s ⏱️
2 suites  0 💤
2 files    0

Results for commit 151fa1c.

Comment on lines +34 to +42
@Override
public void insert(Object data) {
elementData[size] = data;
size++;

if (size == elementData.length) {
grow();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 추가 시 size를 확인 용량을 늘려주었습니다. size가 용량을 넘으면, 2배로 바로 늘려주게 되면 추가로 element를 넣지 않으면 메모리 낭비가 생기지 않을까요? @JAEKWANG97 님의 의견이 궁금해요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 궁금합니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hellomatia 님 좋은 지적 감사드립니다. 말씀해주신 대로, size가 용량을 초과하는 경우 배열 크기를 2배로 늘리는 로직은 실제로 메모리 낭비를 일으킬 수 있습니다. 이 부분에 대해 충분히 고려하지 못했던 것 같습니다. 귀중한 피드백을 통해 많이 배우게 되었습니다. 감사합니다!

@hellomatia hellomatia linked an issue May 30, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrayList를 구현해보자!

4 participants