Using String in Java
What is string ?
String is a sequence of characters. In Java, objects of the String class are immutable which means they cannot be changed once created
Types of string
Strings can be created in two ways:
1. String literals:
These are sequences of characters enclosed in double quotes, for example, "Hello, world!". When the compiler encounters a string literal, it creates a String object automatically.
2. New keyword:
Strings can also be created using the new keyword and the String constructor, for example, String str = new String("Hello, world!")


String method
Java provides several methods for working with strings, including:
length(): Returns the number of characters in the string.
charAt(int index): Returns the character at the specified index.
substring(int beginIndex, int endIndex): Returns a new string that is a substring of this string.
equals(Object another): Compares this string to another object.
concat(String str): Concatenates the specified string to the end of this string.
indexOf(String str): Returns the index within this string of the first occurrence of the specified substring.
replace(char oldChar, char newChar): Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
toUpperCase(): Converts all of the characters in this String to uppercase.
toLowerCase(): Converts all of the characters in this String to lowercase.
trim(): Returns a copy of the string, with leading and trailing whitespace omitted.
contains(CharSequence s): Returns true if and only if this string contains the specified sequence of char values.
split(String regex): Splits this string around matches of the given regular expression.
startsWith(String prefix): Tests if this string starts with the specified prefix.
endsWith(String suffix): Tests if this string ends with the specified suffix.
toCharArray(): Converts this string to a new character array.
valueOf(datatype x): Returns the string representation of the specified datatype value.
toString(): Returns the string itself.

In above program following String methods have been used:
toUpperCase(): Converts all of the characters in this String to uppercase.
toLowerCase(): Converts all of the characters in this String to lowercase.
trim(): Returns a copy of the string, with leading and trailing whitespace omitted.
length(): Returns the number of characters in the string.
substring(int beginIndex, int endIndex): Returns a new string that is a substring of this string.
In the above program length() methods have been used: Returns the number of characters in the string.

In the above program replace(char oldChar, char newChar) has been used, it returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
In above program concat(String str) has been used, it concatenates the specified string to the end of this string.


