Back to Browse

Session - 59 (String methods part-2)

245 views
Dec 1, 2022
46:47

In this session, you can understand: 4. contains(CharSequence s) : boolean - This method returns true if the string contains a sequence of characters, otherwise it will return false. boolean resContains = s2.contains("-"); System.out.println("Contains result = " +resContains); 5. startsWith(String prefix) : boolean - This method will return us true if the String is starting with a given prefix, otherwise false boolean resStartsWith = s2.startsWith("um"); System.out.println("StartsWith reult = " +resStartsWith); 6. endsWith(String suffix) : boolean - This method will return us true if String is ending with a given suffix, otherwise false boolean resEndsWith = s2.endsWith("Cit"); System.out.println("EndsWith result = " +resEndsWith); 7. equalsIgnoreCase(String str) : boolean - This method compares the content of two strings, while comparing it will ignore the case sensitivity. It will return us true if contents are equal, otherwise false boolean eqlIgnrRes = s1.equalsIgnoreCase("mumbai"); System.out.println("EqualsIgnoreCase result = " +eqlIgnrRes); 8. indexOf(Char ch) : int - This method will return us an index in integer format for a given character. char myChar = 'b'; int index = s1.indexOf(myChar); System.out.println("Index of " +myChar + " = " +index); 9. lastIndexOf(char ch) : int - This method will return us the index of the last occurrence of given character System.out.println(s2.lastIndexOf('i'));

Download

1 formats

Video Formats

360pmp467.4 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Session - 59 (String methods part-2) | NatokHD