Sunday, 18 September 2016

String object by using char array

12.5 character array

  • We can create Sting object by using char array.
char ch[] = { 'P','r','a','s','a','d' };  
String name = new String(ch);       
-------------------------------------------------------------------
Program         :        Creating String object by using char array
Program name  :        StringDemo3.java
Output             
                                My name is : Prasad 

class StringDemo3
{
public static void main(String args[])
{
          char ch[] = {'P','r','a','s','a','d'};  
          String name = new String(ch);  

          System.out.println(“My name is:”+name);
}
}

Compile          :          javac StringDemo3.java
Run                :          java StringDemo3
Output            :
                                 My name is : Prasad
-------------------------------------------------------------------

Thanks for your time.
Nireekshan