class
StringMeth
{
public static void main(String args[])
{
String s1 = "This is a
sample String";
String s2 = " Hello
";
String s3 = "Hello
World";
String s4 = "Hello";
String s5 = "HELLO";
System.out.println(s1 +
".length() : " + s1.length());
System.out.println(s1 +
".charAt(2) : " + s1.charAt(2));
System.out.println("Character Array");
char c[] = new
char[s1.length()+3];
c[0] = 'a';c[1] = 'b';c[2] =
'c';
s1.getChars(0,s1.length(),c,2);
for(int i=0;i<c.length;i++)
System.out.print(c[i] +
" ");
System.out.println();
System.out.println("Byte
Array");
byte b[] = new
byte[s3.length()];
s3.getBytes(0,s3.length(),b,0);
for(int i=0;i<b.length;i++)
System.out.print(b[i] +
" ");
System.out.println();
System.out.println(s4 +
".compareTo(" + s3 + ") = " + s4.compareTo(s3));
System.out.println(s3 +
".startsWith(H) = " + s3.startsWith("H"));
System.out.println(s3 + ".endsWith(u)
= " + s3.endsWith("u"));
System.out.println(s3 +
".indexOf(o) = " + s3.indexOf('o'));
System.out.println(s3 +
".indexOf(o,5) = " + s3.indexOf('o',5));
System.out.println(s3 +
".lastIndexOf(o) = " + s3.lastIndexOf('o'));
System.out.println(s3 +
".lastIndexOf(o,6) = " + s3.lastIndexOf('o',6));
System.out.println(s3 +
".substring(2,7) = " + s3.substring(2,7));
System.out.println(s1 +
".concat(s2) = " + s1.concat(s2));
System.out.println(s4 +
".replace(l,w) = " + s4.replace('l','w'));
System.out.println(s4 +
".toUpperCase() = " + s4.toUpperCase());
System.out.println(s5 +
".toLowerCase() = " + s5.toLowerCase());
System.out.println(s2 +
".trim() = " + s2.trim());
}
}
No comments:
Post a Comment