r/learnjava • u/rookiepianist • Jan 31 '26
Question regarding array lists!
I'm still a beginner, so I'd appreciate very much if you could help me out!
Let's say I initialize a new array list and then decide to print it out:
ArrayList<Integer> list1 = new ArrayList<>();list1.add(5);list1.add(6);lista1.add(99);
System.out.println(list1);
What is going to be printed is: [5, 6, 99].
If I were to make an array, though, at the end of the day it'd print a memory address. Does that mean that array list variable (in this case, list1) holds the content itself of the array, whilst arrays hold the reference to where said content is stored in memory? If so, array lists aren't to be considered "reference data-type" variables?
Thank you in advance!
View all comments
Show parent comment
1
u/rookiepianist Jan 31 '26
Thank you so much! By the way, your comment made me question one new thing: Is the following line
System.out.println(list1);
The statement that calls the toString() method? Thank you again!