import java.lang.String.*;
class Strings
{
public static void main(String[] args)
{
String str=new String();
str="hello";
String str2=new String(" am ");
String str3="san";
System.out.println(str+str2+str3);//+ IS USED TO CONCAT THE STRINGS
String s=str.concat(str2); //concat tne strings
System.out.println(s.concat(str3));
int n=str3.length(); //returns the length of given string
System.out.println("length of san is :"+n);
System.out.println("Trim of :"+str3.trim());//deletes leading and tailing string
char ch=str3.charAt(2); //returns char of given positon
System.out.println("char at postion 2 is :"+ch);
int k=str.compareTo("helloo"); //compares two given strings
System.out.println("compatrion of two strings :"+k);
boolean t=str.startsWith("h");//returns true if stars with that
System.out.println("hello is stars with h: "+t);
boolean t1=str.endsWith("h");//returns true if ends with that
System.out.println("hello is ends with h: "+t1);
String sss="hello how is u r hekth is n";
int kk=sss.indexOf("is"); //give the position of first str in given str
System.out.println("give postion of first is in string : "+kk);
int kk1=sss.lastIndexOf("is"); //give the position of last str in given str
System.out.println("give postion of last is in string : "+kk1);
System.out.println(sss);
String sk=sss.replace('h','M');
System.out.println("replace of H with M: "+sk);
System.out.println("to lower string:---"+sk.toLowerCase());
System.out.println("to upper case string:---"+sk.toUpperCase());
// System.out.println("Sub string:------"+sk.subString());
}
}
No comments:
Post a Comment