-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed jv-array-list #1208
base: master
Are you sure you want to change the base?
completed jv-array-list #1208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job overall!
public class ArrayList<T> implements List<T> { | ||
|
||
private static final int DEFAULT_CAPACITY = 10; | ||
private Object[] elements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the parameterized type
private Object[] elements; | |
private T [] elements; |
public class ArrayList<T> implements List<T> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line
if (index < 0 || index >= size) { | ||
throw new ArrayListIndexOutOfBoundsException("Index is out of bounds"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it to a private method checkIndex(int index)
you use this check three times
if (index < 0 || index >= size) { | |
throw new ArrayListIndexOutOfBoundsException("Index is out of bounds"); | |
} | |
if (index < 0 || index >= size) { | |
throw new ArrayListIndexOutOfBoundsException("Index is out of bounds: " + index); | |
} |
|
||
private int indexOf(T element) { | ||
for (int i = 0; i < size; i++) { | ||
if (Objects.equals(elements[i], element)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
I may not have been able to adhere to all the "Try to avoid these common mistakes while solving task", but the task was not easy. I hope for your help if you find any mistakes