Skip to content

Implement ArrayList with core methods: add, addAll, get, set, remove,…#1788

Open
ArtShevchenko89 wants to merge 2 commits into
mate-academy:masterfrom
ArtShevchenko89:jv-array-list-sollution
Open

Implement ArrayList with core methods: add, addAll, get, set, remove,…#1788
ArtShevchenko89 wants to merge 2 commits into
mate-academy:masterfrom
ArtShevchenko89:jv-array-list-sollution

Conversation

@ArtShevchenko89
Copy link
Copy Markdown

… size, and isEmpty. Add helper methods checkIndex and growIfArrayFull

… size, and isEmpty. Add helper methods checkIndex and growIfArrayFull
Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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:

  1. Remove the import java.util.Objects; statement (line 5)
  2. 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

package core.basesyntax;

import java.util.NoSuchElementException;
import java.util.Objects;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace Objects.equals(data[i], element) with manual null-safe equality check. For example: (data[i] == null ? element == null : data[i].equals(element))

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants