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); } } |
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() |