Java Tutorial
🔍
What is OOP?Classes & ObjectsConstructorsAccess Modifiersthis Keywordstatic KeywordEncapsulationInheritancesuper KeywordMethod OverridingOverloading vs OverridingPolymorphismUpcasting & Downcastinginstanceof OperatorAbstractionAbstract ClassesInterfacesMarker InterfacesAbstract Class vs InterfaceObject ClasstoString() Methodequals() & hashCode()
Collections OverviewCollections HierarchyIterable InterfaceCollection InterfaceMap Interfaceequals() and hashCode()IteratorListIteratorFail-fast vs Fail-safe IteratorConcurrentModificationExceptionArrayListLinkedListHashSetLinkedHashSetTreeSetQueuePriorityQueueDequeArrayDequeHashMapLinkedHashMapTreeMapConcurrentHashMapCopyOnWriteArrayListList vs Set vs MapChoosing the Right CollectionComparableComparatorComparable vs ComparatorCollections Utility ClassArrays Utility ClassImmutable CollectionsCollection vs CollectionsVectorHashtableStackArrayList Internal WorkingLinkedList Internal WorkingHashMap Internal WorkingTreeMap Internal Working
Print Multiple Lines in Java
beginner· Basics & I/O · Fundamentals
Problem
Each call to System.out.println() automatically adds a newline after the text it prints, so multiple calls appear on separate lines.
Print three separate lines of text to the console.
Input
—
Output
Line 1
Line 2
Line 3
Java Program
Java
public class PrintMultipleLines {
public static void main(String[] args) {
System.out.println("Line 1");
System.out.println("Line 2");
System.out.println("Line 3"); // each call starts on a fresh line
}
}Output
Line 1
Line 2
Line 3
Core Logic
Calling println() once per line is the most direct way to print several lines — each call ends with its own newline.
How It Works
- 1The first
println("Line 1")prints the text and moves the cursor to a new line. - 2The next
println()call starts writing from that new line, and does the same again. - 3Repeating the call for each line builds up the full multi-line output.
Three separate
println() calls produce three separate lines in the console, in the order they were called.💡
Key Point: print() (without ln) would leave the cursor on the same line — the "ln" in println is what adds the newline automatically.
Key Concepts
System.out.println()newline