Java Tutorial3:Demonstration of String methods.


following tutorial is to demonstrate string functions such as string.length(),string.charAt(n);

public class string {
 public static void main(String argv[]) {
 String strOb1 = "BhUSHAN";
 String strOb2 = "SoNAWANE";
 String strOb3 = strOb1;
 System.out.println("Length of strOb1: " +strOb1.length());
 int len;
 len=strOb1.length();
 for(int i=0;i<len;i++)
 System.out.println("Char at index "+i+" in strOb1: " +strOb1.charAt(i));
 if(strOb1.equals(strOb2))
 System.out.println("strOb1 == strOb2");
 else
 System.out.println("strOb1 != strOb2");

if(strOb1.equals(strOb3))
 System.out.println("strOb1 == strOb3");
 else
 System.out.println("strOb1 != strOb3");

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s