Wednesday, November 21, 2012

String functionsin java

String functionsin java

class stri
{
public static void main(String args[])
{
String s1="Rekha";
String s2="Meena";
String s3="Jashmin";
String s4=s2;
System.out.println("String Operation\n");
System.out.println("String S1 is: "+s1);
System.out.println("String S2 is: "+s2);
System.out.println("String S3 is: "+s3);
System.out.println("String S4 is: "+s4);
System.out.println("Length of String S1 is: "+s1.length());
System.out.println("Length of String S2 is: "+s2.length());
System.out.println("Length of String S3 is: "+s3.length());
System.out.println("Length of String S4 is: "+s4.length());

if(s2.equals(s4))
System.out.println("String S2 and s4 is equal");
else
System.out.println("String S2 and s4 is not-equal");

System.out.println("3rd position of String S1 is: "+s1.charAt(4));
System.out.println("Joining String S1 and s2 :"+(s1+s2));
}
}




OUTPUT

String Operation

String S1 is: Rekha
String S2 is: Meena
String S3 is: Jashmin
String S4 is: Meena
Length of String S1 is: 5
Length of String S2 is: 5
Length of String S3 is: 7
Length of String S4 is: 5
String S2 and s4 is equal
3rd position of String S1 is: a
Joining String S1 and s2 :RekhaMeena

0 comments:

Post a Comment