// Java code to illustrate different constructors and methods in String class
import [Link].*;
import [Link].*;
class Test
public static void main (String[] args)
String s= "CSMSSS";
// or String s= new String ("Artificial");
// Returns the number of characters in the String.
[Link]("String length = " + [Link]());
// Returns the character at ith index.
[Link]("Character at 3rd position = "
+ [Link](3));
// Return the substring from the ith index character
// to end of string
[Link]("Substring " + [Link](3));
// Returns the substring from i to j-1 index.
[Link]("Substring = " + [Link](2,5));
// Concatenates string2 to the end of string1.
String s1 = "Csmss";
String s2 = "polytechnic";
[Link]("Concatenated string = " +
[Link](s2));
// Returns the index within the string
// of the first occurrence of the specified string.
String s4 = "Learn Share Learn";
[Link]("Index of Share " +
[Link]("Share"));
// Returns the index within the string of the
// first occurrence of the specified string,
// starting at the specified index.
[Link]("Index of a = " +
[Link]('a',3));
// Checking equality of Strings
Boolean out = "Csmss".equals("csmss");
[Link]("Checking Equality " + out);
out = "Csmss".equals("csmss");
[Link]("Checking Equality " + out);
out = "Csmss".equalsIgnoreCase(" csmss");
[Link]("Checking Equality " + out);
//If ASCII difference is zero then the two strings are similar
int out1 = [Link](s2);
[Link]("the difference between ASCII value is="+out1);
// Converting cases
String w1 = "CSMSS";
[Link]("Changing to lower Case " +
[Link]());
// Converting cases
String w2 = "csmss";
[Link]("Changing to UPPER Case " +
[Link]());
// Trimming the word
String w4 = " Learn Share Learn ";
[Link]("Trim the word " + [Link]());
// Replacing characters
String str1 = "csmsscop";
[Link]("Original String " + str1);
String str2 = "csmsscop".replace('m' ,'j') ;
[Link]("Replaced m with j -> " + str2);