//String Class Methods
class StringDemo
{
public static void main(String[]args)
{
// String create in three ways
String s1="The java";
String s2=new String("I like it");
char arr[]={'s','h','a','s','h','i','k','a','n','t'};
String s3=new String(arr);
// display all the three string
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
//find the lenght of first string
System.out.println("Length of s1"+s1.length());
// Concoarated two string
System.out.println("s1 and s2"+s1.concat(s2));
// concorated three string with +
System.out.println(s1+"from"+s3);
// if test String s1 start with A
boolean x=s1.startsWith("A");
if(x)
System.out.println("s1 starts with \'A\'");
else
System.out.println("s1 does not start with \'A\'");
// extract substring from s2 stating from 0th char to 6th char
String p=s2.substring(0,7);
String q=s3.substring(0,10);
System.out.println(p+q);
// convert s1 into uppercase to lowercase
System.out.println("Upper s1"+s1.toUpperCase());
System.out.println("Lower s1"+s1.toLowerCase());
}
}
class StringDemo
{
public static void main(String[]args)
{
// String create in three ways
String s1="The java";
String s2=new String("I like it");
char arr[]={'s','h','a','s','h','i','k','a','n','t'};
String s3=new String(arr);
// display all the three string
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
//find the lenght of first string
System.out.println("Length of s1"+s1.length());
// Concoarated two string
System.out.println("s1 and s2"+s1.concat(s2));
// concorated three string with +
System.out.println(s1+"from"+s3);
// if test String s1 start with A
boolean x=s1.startsWith("A");
if(x)
System.out.println("s1 starts with \'A\'");
else
System.out.println("s1 does not start with \'A\'");
// extract substring from s2 stating from 0th char to 6th char
String p=s2.substring(0,7);
String q=s3.substring(0,10);
System.out.println(p+q);
// convert s1 into uppercase to lowercase
System.out.println("Upper s1"+s1.toUpperCase());
System.out.println("Lower s1"+s1.toLowerCase());
}
}
0 comments:
Post a Comment