Find A Substring In A String Java

[Solved] Find A Substring In A String Java | Swift - Code Explorer | yomemimo.com
Question : Java Program to Illustrate How to Find a Substring // in the String using contains() Method

Answered by : deepika-sahu

// Java Program to Illustrate How to Find a Substring
// in the String using contains() Method
 
// Importing required classes
import java.io.*;
import java.lang.*;
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
        // String in which substring
        // to be searched
        String test = "software";
 
        CharSequence seq = "soft";
        boolean bool = test.contains(seq);
        System.out.println("Found soft?: " + bool);
 
        // Returns true substring if found.
        boolean seqFound = test.contains("war");
        System.out.println("Found war? " + seqFound);
 
        // Returns true substring if found
        // otherwise return false
        boolean sqFound = test.contains("wr");
        System.out.println("Found wr?: " + sqFound);
    }
}

Source : https://www.geeksforgeeks.org/searching-for-characters-and-substring-in-a-string-in-java/?ref=lbp | Last Update : Sat, 31 Dec 22

Answers related to find a substring in a string java

Code Explorer Popular Question For Swift