Strings , which are widely used in Java programming, are nothing but a sequence of characters.
In this topic we will discuss, what is a
String and how to assign a value to String .Creating Strings : String s = "Hello World"; String is the data type and s is the reference which refers to the data "Hello World" . There is also another way of creating Strings. The syntax is as shown below. Syntax : String s = new String("Hello World"); When we declare a string variable and assign some value, it means that we are creating a string object which cannot be changed. Whenever we modify the String a new String object is created with the modifications, and the original string is left as it is. Anyway Java provides String Buffer, StringBuilder Class In Java classes where strings(character sequences) can be modified even after they are created. We can also create a String object from char as well as byte arrays as shown below.
char c[] = {'j', 'a', 'v', 'a'}; For byte array: byte b[] = {65, 66, 67, 68}; CreatingStrings CODE class CreatingStrings OUTPUT ~~ DESCRIPTION At THINGS TO TRY
Dependent Topics :
|