String In Java - Tutorials For WebDriver

We lead maintain learnt about DIFFERENT DATA TYPES IN JAVA In my past times post. Now, Many peoples are agreement that Java String Is also a information type. Let me right them -> String Is non information type inward coffee software evolution language. If string Is non information types too thence what Is String? This interrogation tin ship away locomote asked past times Interviewer too. Strings are objects prepared past times sequence of characters. The java.lang has String shape to exercise too manipulate strings. String class has many Inbuilt functions which nosotros tin ship away usage to perform dissimilar actions on string.

If y'all don't know, Let me tell y'all that nosotros lead maintain to piece of job amongst strings really often In selenium WebDriver tests for software application. So y'all must lead maintain noesis of useful functions of String shape to usage them In your selenium webdriver software seek instance development. Let us lead maintain elementary instance of String to sympathise dissimilar methods of String shape inward coffee software evolution language.

public shape Strng_Example {   populace static void main(String[] args) {      String st1 = "This World is Very Nice";   String st2 = " And Beautiful.";      //Comparing ii strings. Return truthful If both gibe else provide false.   System.out.println("st1 equals to st2? -> "+st1.equals(st2));      //Concatenates st2 amongst st1.   System.out.println("Concatenation of st1 too st2 Is -> "+st1.concat(st2));      //Retrieve the ninth Indexed grapheme from string.   System.out.println("Character at Index nine Is -> "+st1.charAt(9));      //Find the length of string.   System.out.println("Length Of St1 -> "+st1.length());      //Converting whole string In lower case.   System.out.println("String In Lowercase -> "+st1.toLowerCase());      //Converting whole string In upper case.   System.out.println("String In upper-case missive of the alphabet -> "+st1.toUpperCase());      //Retrieve the Index of firstly 'i' character.   System.out.println("Index of 1st charater i Is -> "+st1.indexOf('i'));      //Retrieve the index of sec most 'i' character.   System.out.println("Index of sec charater i Is -> "+st1.indexOf('i', 3));      //Retrieve the Index of give-and-take 'Very' from string.   System.out.println("Index of give-and-take Very Is -> "+st1.indexOf("Very"));      //Converting value From int to string.   int j = 75;   String val2 = String.valueOf(j);   System.out.println("Value Of string val2 Is -> "+val2);      //Converting string to integer.   String val1="50";   int i = Integer.parseInt(val1);   System.out.println("Value Of int i Is -> "+i);      //Print the String starting from fifth Index to twelfth Index.   System.out.println("Retrieving sub string from string -> "+st1.substring(5, 13));      //Split string.    String splt[] = st1.split("Very");   System.out.println("String Part i Is -> "+splt[0]);   System.out.println("String Part 2 Is -> "+splt[1]);                   //Trim String.   System.out.println("Trimmed st2 -> "+st2.trim());   } }

If y'all volition await at inward a higher house example, I lead maintain prepared dissimilar examples of string method to lead maintain some activity or nosotros tin ship away state operations on string. Sort explanation of all inward a higher house string methods are equally bellow.

Two String Comparison
To compare ii strings, nosotros tin ship away usage syntax like st1.equals(st2). It volition provide True If both strings are same else It volition provide False.

Two String Concatenation
Syntax st1.concat(st2) volition concatenate st1 amongst st2.

Retrieving Character from Index
Syntax st1.charAt(9)) volition hollo back the grapheme from string st1 located at ninth Index. Index Starts from 0.

Length Of String
st1.length() volition provide lenght of string st1.

Convert String In Lower Case Letters
st1.toLowerCase() volition convert whole string letters In lower case.

Convert String In UpperCase Letters
st1.toUpperCase() volition convert whole string letters In upper case.

Retrieving Index Of 1st most character
st1.indexOf('i') volition hollo back Index of firstly most grapheme 'i' from string.

Retrieving Index Of sec most character
st1.indexOf('i', 3)) volition hollo back Index of minute most grapheme 'i' from string. iii described the from Index agency It volition stimulate down finding grapheme 'i' from Index 3. First 'i' has Index 2 thence nosotros demand to usage iii to honor sec most character.

Retrieving Index Of specific give-and-take from string
st1.indexOf("Very") volition hollo back index of give-and-take 'Very' from string.

Convert from Integer To String
String.valueOf(j) volition convert value of 'j' from int to string.

Convert from String To Integer
Integer.parseInt(val1) volition conver value of 'val1' from string to int.

Retrieving sub string from string
Syntax st1.substring(5, 13) volition hollo back string from Index v To Index 13.

Split String
String splt[] = st1.split("Very") volition separate string st1 from give-and-take 'Very' too shop both strings In array.

Trim String
If string has white infinite at showtime or halt of the string too thence y'all tin ship away usage cut down business office like st2.trim() to take away that white space.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post