how to print a String[] in java code example
Example 1: print in java
System.out.println("text");
System.out.println(String);
System.out.print("text");
System.out.print(String);
Example 2: java print array
System.out.println(Arrays.toString(arr));
Example 3: how to print string array in java
import java.util.Arrays;
public class Printarray{
public static void main(String[] args){
String[] arr = new String[]{"Mumbai","Delhi","Kolkata","Chennai"};
for(int i=0; i<arr.length;i++){
System.out.println(arr[i]);
}
for(String city:arr){
System.out.println(city);
}
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.deepToString(arr));
System.out.println(Arrays.asList(arr));
}
}
Example 4: how to print something in java
System.out.print("one");
System.out.print("two");
System.out.println("three");
Example 5: print statement in java
System.out.println("Hello!");
System.out.print("Hello!!");
Example 6: print in java
System.out.println(String someString);