Professional Documents
Culture Documents
11 & 12
Program Code: Write a program to show the use of all methods of String
class
class extest{
System.out.println(str);
System.out.println(str1);
System.out.println(str.charAt(2) );
System.out.println(str.length() );
System.out.println(str.substring(1) );
System.out.println(str.substring(1,2) );
System.out.println(str.startsWith("Ku") );
System.out.println(str.endsWith("abc") );
System.out.println(str.equals("Kunal") );
System.out.println(str.equalsIgnoreCase("Kunal") );
//System.out.println(str1.IndexOf('e') );
System.out.println(str1.lastIndexOf('e') );
System.out.println("Hello".concat(str) );
System.out.println(str.compareTo(str1) );
System.out.println(str.toLowerCase() );
System.out.println(str.toUpperCase() );
System.out.println(str.replace("I", "M") );
System.out.println(str.contains("Info") );
System.out.println("Hllo".trim() );
}}
Exercise:
1. Write output of the following code:
class String_Demo{
System.out.println(s);
}}
class Output{
}}
2. Write a program to implement all methods of StringBuffer class
class StrBuff {
str.setCharAt(0, 'J');
str.setLength(8);
}}