String Constructors Java

String Constructors Java


In Java, a String object can be created a number of ways. The most frequently used styles are shown here using 9 types of String constructors (including StringBuffer and StringBuilder) defined java.lang.String API.

The 9 constructors are

1. public java.lang.String();
2. public java.lang.String(java.lang.String);
3. public java.lang.String(char[]);
4. public java.lang.String(char[], int startIndex, int numChars);
5. public java.lang.String(int[], int, int);
6. public java.lang.String(byte[]);
7. public java.lang.String(byte[], int startIndex, int numInts);
8. public java.lang.String(java.lang.StringBuffer);
9. public java.lang.String(java.lang.StringBuilder);

The following is the example code using the above 9 string constructors


String Constructors Java
Output screen on String Constructors Java

Also you may be interested in Java StringBuffer Constructors

2 thoughts on “String Constructors Java

  1. vijaylaksshmi

    when array element of object is intialized at the time declaration without using new operator,
    is the object considered as reference variable or object.

Leave a Reply

Your email address will not be published. Required fields are marked *