Thursday, June 16, 2011

PROGRAM TO DEMONSTRATE THE USE OF STRING CLASS AND EMPLOYING AT LEAST 10 STRING HANDLING METHODS


class StringMethods
{    public static void main(String args[ ])
{    String string1 = new String ("WELCOME TO");
String string2 = new String (" JAVA PROGRAMMING");
String s3,s4,s5,s6,s7,s8;
boolean b;
char ch;
int a,c;
System.out.println("\n\nSTRING1 is  : "+string1);
s3 = string1.toLowerCase();
System.out.println("\n\nSTRING1 is Converted into Lower Case       : "+s3);
s4 = string1.toUpperCase();
System.out.println("\n\nSTRING1 is Converted into Upper Case       : "+s4);
s5 = string1.replace ('O','A');
System.out.println("\n\nSTRING1's character 'O' is Replaced by 'A'  : "+s5);
a = string1.length();
System.out.println("\n\nLength of The STRING1  is                  : "+a);
ch = string1.charAt(5);
System.out.println("\n\nThe Character Present at Index value = 5 in the STRING1 is : "+ch);
s7 = string1.substring(5);
System.out.println("\n\nThe Substring  Starting from index value = 5 of STRING1 is :"+s7);
s6 = string1.trim();
System.out.println("\n\nAfter Remove White Spaces at the Beg. and End of the STRING1 is : "+s6);
System.out.println("\n\nSTRING2 is  : "+string2);
b  = string1.equals(string2);
System.out.println("\n\nAre Both Strings Equal? True  or  False    : "+b);
s6 = string1.concat (string2);
System.out.println("\n\nThe Concatenates of  STRING1 &  STRING2 is : "+s6);
s8 = string2.substring(5,11);
System.out.println("\n\nThe Substring Start from index value = 5 to 11 of STRING2 : "+s8); //Not including 11th index value
}
}

No comments:

Post a Comment