Computer Applications
Differentiate between startsWith() and endsWith().
Java String Handling
2 Likes
Answer
startsWith() | endsWith() |
---|---|
startsWith() tests if the string object starts with the string specified as its argument. | endsWith() tests if the string object ends with the string specified as its argument. |
Example: String str = "ICSE Computer Applications"; boolean res = str.startsWith("ICSE"); System.out.println(res); The output of this code is true as str begins with "ICSE". | Example: String str = "ICSE Computer Applications"; boolean res = str.endsWith("tions"); System.out.println(res); The output of this code is true as str ends with "tions". |
Answered By
2 Likes