how to create a char array in java and print them.


import java.util.;
import java.io.
;

class MainClass
{
public static void main(String[] args) throws IOException
{
String s="Welcome";

//1.this is the first method to create char array by using toCharArray()method

char[] ch=s.toCharArray();
int n=s.length();

//2.this is the another method to assign the string into char array by using loop and 
//chatAt() method.

char[] chh=new char[n];
for(int i=0;i<n;i++)
{
  chh[i]=s.charAt(i);
}
//never try this System.out.println(s+" "+ch);
//it will print string s but it will not print literals of char array ch
//so to print char array always use System.out.println(ch);
System.out.println(chh);
System.out.println(s);
System.out.println(ch);
for(int i=0;ch!=null;++i)
{
  System.out.print(ch[i]);
}
System.out.println();

}
}