Java – Important Constructors of String Class | Code Factory


Index Page : Link

Donate : Link

Medium Link : Link

Applications : Link

1. String s = new String();

Create an empty String object in Heap

2. String s = new String(String literal);

For given String literal equivalent object will be created in Heap area

Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.

3. String s = new String(StringBuffer sb);

Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.

4. String s = new String(StringBuilder sb);

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

5. String s = new String(char[] ch);

Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.

6. String s = new String(byte[] b);

Constructs a new String by decoding the specified array of bytes using the platform’s default charset.

Reference : Link

One thought on “Java – Important Constructors of String Class | Code Factory”

Leave a comment