Thursday, 17 August 2017

The Java
String data type can have a sequence (string) of characters, like pearls on
a string. Strings are how work with text in Java.

Strings
in Java are symbolizes inside using bytes, encoded as UTF-16. UTF-16 uses 2
bytes to represent a single character. UTF is a character encoding that can
represent characters from a lot of different languages (alphabets).

Syntax

char[] ch={'h’,'e','l','l','o','t','n','c'};

String s=new String(ch);

There
are two ways to create String object:

By string literal

By new keyword

By string literal :

A String object
is an individual instance of the java.lang.String class

Syntax

String s=" techNewsNcareer ";

By new keyword

it
will creates two objects and one reference variable.

Syntax

String str3 = new
String("techNewsNcareer");

Initialization of
String:

JVM
keep a memory pool for String. When you create a String, first this memory pool
is scanned. If the instance previously exists then this new instance is mapped
to the already existing instance. If not, a new java String instance is created
in the memory pool.

Syntax

String str1 =
"techNewsNcareer";

String srt2 = new String();

String str3 = new String("techNewsNcareer");

String str4 = new String(char[]);

String str5 = new String(byte[]);

String str6 = new String(new
StringBuffer());

String str7 = new String(new
StringBuilder());

Methods of string
class :

The
java.lang.String class provides many useful methods to perform operations on
sequence of char values.