हिंदी

How does endsWith() and startsWith() differ? Explain with an example.

Advertisements
Advertisements

प्रश्न

How does endsWith() and startsWith() differ? Explain with an example.

कोड लेखन
Advertisements

उत्तर

starts With() returns true if a provided string is used as a prefix for another string, and false otherwise.

Example1:

Strings 1 = "Monopoly";
String s2 = "Mono";
System.out.println(s1.starts With(s2));
Output: true
endsWith(): It returns true if a given string is used as a suffix to another string, false otherwise.
Example2: 
String s1 = "Monopoly";
String s2 = "poly";
System.out.println(s1.endsWith(s2));
Output: true  
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: String Handling - EXERCISES [पृष्ठ २८९]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 4 String Handling
EXERCISES | Q VII. 5. | पृष्ठ २८९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×