//I have written this method but I don't know how to proceed.
public static void print(ArrayList<Integer> list) {
for (int i=0;i<list.size();i++) {
System.out.print(list.get(i));
Asked
Active
Viewed 279 times
-2

khelwood
- 55,782
- 14
- 81
- 108
-
3`println`........ – Eran Mar 11 '19 at 09:16
-
`println` is an equivalent of `print` which adds `\n` at the end of the line (hence the name... ~ `print\n`) – Arnaud Denoyelle Mar 11 '19 at 09:18
-
@ArnaudDenoyelle to be picky, it adds the JVM's configured line separator, which is often `\n`, but could be anything else (e.g. `\r\n` on Windows). – Andy Turner Mar 11 '19 at 09:20
-
1I believe it’s short for “print line”. `ln` has been taken over from standard libraries for other programming languages including Pascal. – Ole V.V. Mar 11 '19 at 09:23
1 Answers
2
By using
System.out.println(list.get(i));
instead of
System.out.print(list.get(i));
the println
method adds a linebreak after what you print.

Stultuske
- 9,296
- 1
- 25
- 37
-
-
Ankit, why would one do that? it doesn't make the code clearer, just messier. – Stultuske Mar 11 '19 at 09:36
-
just an alternative...seems the user is newbie stucking at small points.. Help him to show him alternatives :) – Ankit Mar 11 '19 at 09:38
-
yes, but that is not "an alternative". to prevent having to do something like that, println was created. – Stultuske Mar 11 '19 at 09:39
-