Skip to content

Commit d425aa3

Browse files
Add getData() method to display all data in array list.
1 parent 52dc465 commit d425aa3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

list/ArrayList.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public E get(int i) throws IndexOutOfBoundsException {
4444
}
4545

4646
public void getData() {
47-
for (int i = 0; i < data.length; i++) {
48-
int j = i + 1;
49-
System.out.println("Element at: " + (j) + " is: " + data[i]);
47+
for (int i = 0; i < size; i++) {
48+
System.out.println("Element at: " + (i + 1) + " is: " + data[i]);
5049
}
5150
}
5251

0 commit comments

Comments
 (0)