Strings

 package JavaPra;


public class StingEx {
public static void main(String[] args) {
String name = "Myra Nirvana";
System.out.println(name);
// length of the string
System.out.println(name.length());//12

//Concatenate the String
String s1 = "Welcome";
String s2="to my world";
//join 2 strings
System.out.println(s1+s2);
System.out.println(s1.concat(s2));
String s3= "Automation";
System.out.println(s1.concat(s2).concat(s3));

String s4= " SDET ";
// trim the left and right values
System.out.println("before Trim"+s4);
s4.trim();
System.out.println(s4.length());
System.out.println("after Trim");
System.out.println(s4.trim().length()+s4.trim());
System.out.println(name.charAt(7));
for (int i = 0; i < name.length(); i++) {
System.out.print(name.charAt(i));
System.out.println(" ");
}

//contains()-- retuns boolean value - true or false

System.out.println(s1.contains("welcome"));
System.out.println(name.contains("My"));

//equals, equalIgnorecase()- compare 2 strings
//retuns boolean values.
String namea = "Sudheer";
String nameb="sudheeR";

System.out.println(namea.equals(nameb));
System.out.println(namea.equalsIgnoreCase(nameb));

//replace()=== replace single or multiple charater from string
String namec= namea.replace('S','X');
System.out.println(namec+ " Replace s with 'X'");
System.out.println(name.replace("Nirvana","Nirvana Chittireddy"));

//Substring
//start index we count with 0 and end index we count with 1

System.out.println( name.substring(4));
System.out.println(name.substring(0,9));
String language= "Programming";

System.out.println(language.substring(0,5));

//split- divide the string into multiple parts using delimeter.
// cannot use as delimeter - * $ + -
String Splitname = "SudheerKumarReddy@gmail.com";
Object[]inee = Splitname.split("@");
for (Object aa:inee) {
System.out.println(aa);
if (aa.equals("SudheerKumarReddy")){
System.out.println(" Is available "+ aa);
}

}

String country = "united states of america";

System.out.println(country.toUpperCase().charAt(9));

String aa= "abc";
String bb= new String("abc");
String cc= bb;
System.out.println(aa);
System.out.println(bb);
System.out.println(cc);
//equals - comapares values of the object
// ==--> compares the onjects
System.out.println(aa==bb);//false
System.out.println(aa.equals(bb));//true
System.out.println(bb==cc);//true
System.out.println(bb.equals(cc));//true
System.out.println(aa==cc);//false
System.out.println(aa.equals(cc));//true
}
}

Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium