Implement ArrayList with core methods: add, addAll, get, set, remove,…#1788
Implement ArrayList with core methods: add, addAll, get, set, remove,…#1788ArtShevchenko89 wants to merge 2 commits into
Conversation
… size, and isEmpty. Add helper methods checkIndex and growIfArrayFull
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The implementation shows solid understanding of custom collection design with proper structure, constants, and exception handling. However, one critical checklist violation blocks approval.
Critical Issue
Prohibited utility class usage: The code imports and calls java.util.Objects.equals() at line 96, which directly violates the checklist requirement: "Do NOT use Objects, Arrays, or any other util class." You must:
- Remove the
import java.util.Objects;statement (line 5) - Replace
Objects.equals(data[i], element)with a manual null-safe equality check
Example fix:
// Instead of Objects.equals(data[i], element)
(data[i] == null ? element == null : data[i].equals(element))Minor Improvement
When element is null, the loop will call data[i].equals(null) which returns false safely. However, for clarity and consistency, you could add an explicit null check:
if ((data[i] == null && element == null) || (data[i] != null && data[i].equals(element)))Once you remove the Objects import and replace the equality check, the implementation will meet all requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| package core.basesyntax; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
| import java.util.Objects; |
There was a problem hiding this comment.
The checklist explicitly states 'Don't use Objects, Arrays, or any other util class.' This import must be removed.
| public T remove(T element) { | ||
| return null; | ||
| for (int i = 0; i < size; i++) { | ||
| if (Objects.equals(data[i], element)) { |
There was a problem hiding this comment.
Replace Objects.equals(data[i], element) with manual null-safe equality check. For example: (data[i] == null ? element == null : data[i].equals(element))
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved. All checklist requirements are now satisfied: the java.util.Objects import has been removed, manual null-safe equality check (data[i] == null && element == null) || (data[i] != null && data[i].equals(element)) is properly implemented, proper constants (DEFAULT_CAPACITY, GROWTH_FACTOR) are used, DRY principles are followed with checkIndex() and growIfArrayFull() helper methods, System.arraycopy() is used correctly for array manipulation, and informative exception messages are provided throughout. The ArrayList implementation is complete and ready for use.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
… size, and isEmpty. Add helper methods checkIndex and growIfArrayFull