Simple example to use string in different ways.
Syntax :
String variable_name = "Hello World!"
Example :
- public class String_Demo{
- public static void main(String args[]){
- char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
- String helloString = new String(helloArray);
- System.out.println( helloString );
- }
- }
Description :
Step 1:Starting of class
Step 2:Start of main function.
Step 3:Define a character array
Step 4:Defining and initializing "helloString". Here value of the variable "Hello array" is copied to the String variable "helloString".
Step 5:Display content of variable "helloString" to console.