How to Print or Output a String in Java?

In Java, we can simply use System.out.println() or System.out.print() methods to print the string, where,

  • System is a class
  • out is a public static field: it accepts output data.

Java




/*package whatever //do not write package name here */
 
import java.io.*;
 
class GFG {
    public static void main(String[] args)
    {
        String str = "w3wiki";
 
        // Printing on same line using print()
        System.out.print("String: ");
        System.out.print(str);
 
        // Printing on next line using println()
        System.out.println("\nString: ");
        System.out.println(str);
    }
}


Output

String: w3wiki
String: 
w3wiki

How to print or output a String?

In this article, we are going to learn how to print or output a string using different languages. Strings are considered a data type in general and are typically represented as arrays of bytes (or words) that store a sequence of characters. Strings are defined as an array of characters

Topics:

Language Used

Function or Classes

How to Print or Output a String in C

printf()

How to Print or Output a String in C++

cout<<

How to Print or Output a String in Java

System.out.println() or System.out.print()

How to Print or Output a String in C#

Console.Write() or Console.WriteLine()

How to Print or Output a String in Python

print()

How to Print or Output a String in JavaScript

console. log()

Similar Reads

How to Print or Output a String in C?

We can use the printf() function to print a string in C language. It takes the string as an argument in double quotes (” “)....

How to Print or Output a String in C++?

...

How to Print or Output a String in Java?

To print the string, just place the string (the variable that stores the string’s value) after cout<<, as shown here in the following program....

How to Print or Output a String in C#?

...

How to Print or Output a String in Python?

In Java, we can simply use System.out.println() or System.out.print() methods to print the string, where,...

How to Print or Output a String in JavaScript?

...