Learn Selenium and Java for Selenium

Sunday, 8 July 2018

Strings in Java : Part 7

String Methods

Remember our last post focused on usage of split() method in string in case you have missed seeing that you can see our Strings in Java : Part 6 Post , now we are going to explain some of the easy and most commonly used string methods here ,

  • String toLowerCase()
    • This method converts all the character in string to the lower case
  • String toUpper()
    • This method converts all the character in string to the upper case
  • String concat()
    • This method is used to combine two strings
  • String replace()
    • This method is used to replace a old character with new character
  • String compareTo()
    • This method is used to compare given string to current string and this method can return positive, negative or zero values


Let us understand the usage of methods used above using below program :


public class Main{  
public static void main(String args[]){  

String s1="Learn Selenium Automation";
String s2="Selenium ";

String lower = s1.toLowerCase(s1);
String upper =s1.toUpper(s1);
String replace =s1.replace('L', 'T');
String concat=s1.concat("Easily");

System.out.println(s1.compareTo(s2));
System.out.println(upper);
System.out.println(lower);
System.out.println(replace);
System.out.println(concat);

 }
}  

The output of the above program is 

-6
LEARN SELENIUM AUTOMATION
learnseleniumautomation
Tearn Selenium Automation
Learn Selenium Automation Easily


Hope you have understood the Post if there is any doubt please feel free to add the comments section we would answer your queries :)

0 comments:

Post a Comment

Popular Posts

Recent Posts



Newsletter

Join our newsletter to get secret tips directly in your inbox!


*We Hate Spam!

Powered by Blogger.