Creating String Object from Character Array in Java

Java 8Object Oriented ProgrammingProgramming

Here is our character array.

char[] ch = { 'T', 'E', 'S', 'T'};

To create string object from the above character array is quite easy. Add the array to the string parameter as shown below −

String str = new String(ch);

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      char[] ch = { 'T', 'E', 'S', 'T'};
      String str = new String(ch);
      System.out.println(str);
   }
}

Output

TEST
raja
Published on 14-Dec-2018 06:36:26
Advertisements