File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how System.out.println(ArrayList al) works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how System.out.println(ArrayList al) works?" Watch "how System.out.println(ArrayList al) works?" New topic
Author

how System.out.println(ArrayList al) works?

jaspreet atwal
Ranch Hand

Joined: Sep 05, 2007
Posts: 52
I have realized that if I use the above method on an existing ArrayList, System.out.println will print each element there in my ArrayList. e.g I have an ArrayList as below:



and I pass it to System.out.println(), it will print each element in the ArrayList. How does it make it possible.



Still Learing..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36556
    
  16
Find your Java installation folder and explore it until you find a file called "src.zip". Unzip it into a folder called src, then explore to find the java folder then the util folder then the ArrayList file then read the toString() method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36556
    
  16
Actually go into the AbstractCollection class and look for the toString() method.
jaspreet atwal
Ranch Hand

Joined: Sep 05, 2007
Posts: 52
That answers my question, Thank you!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36556
    
  16
Originally posted by jaspreet atwal:
That answers my question, Thank you!!
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how System.out.println(ArrayList al) works?
 
Similar Threads
List with a sublist of Integers
Generics
New ArrayList Problem
Using for..each loop on Object[]
Iterate Hashmap through struts