Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**This example shows how we can search a word within a String object using indexOf() method which returns a position index of a word within the string if found. Otherwise it returns -1.
- **/
- public class SearchStringEmp{
- public static void main(String[] args) {
- String strOrig = "Hello readers";
- int intIndex = strOrig.indexOf("Hello");
- if(intIndex == - 1) {
- System.out.println("Hello not found");
- } else {
- System.out.println("Found Hello at index " + intIndex);
- }
- }
- }
- //This example shows how we can search a word within a String object
- public class HelloWorld {
- public static void main(String[] args) {
- String text = "The cat is on the table";
- System.out.print(text.contains("the"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement