Friday, August 16, 2013

java Program to Illustrate the use of Methods of String Class

Program to Illustrate the use of Methods of String Class
import java.io.*;
class String1
{
public static void main(String arg[])
{
try
{
int n = 5;
int m = 8;
char s = 'n';
String str = new String(" Radha");
String str3 = new String(" Radha ");
String str4;
System.out.println(str.equals(str3));
String str1 = str.toLowerCase();
System.out.println("The String in Lower case:"
+ str1);
String str2 = str1.toUpperCase();
System.out.println("The String in Upper case:"
+ str2);
str4 = str1.trim();
System.out.println("The String after trimming:"
+ str4);
System.out.println("The length of String:"
+ str4.length());
str2 = str1.replace('h','d');
System.out.println("The repalced String" + str2);
System.out.println(str1.equals(str2));
System.out.println("The character at position 3:"
+ str2.charAt(3));System.out.println("The substring is:"
+ str2.substring(n));
System.out.println("The substring is:"+ str2.substring(n,m));
System.out.println("The Index of O:"+ str2.indexOf(s));
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
}

No comments:

Post a Comment