This is a java program to perform search using string library.
Here is the source code of the Java Program to Perform String Matching Using String Library. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
package com.maixuanviet.setandstring;
import java.util.Scanner;
public class StringSearchUsingStrLib
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the main string: ");
String text = sc.nextLine();
System.out.println("Enter the pattern string: ");
String pattern = sc.nextLine();
for (int i = 0; i <= (text.length() - pattern.length()); i++)
{
if (text.substring(i, (i + pattern.length())).equalsIgnoreCase(
pattern))
{
System.out.println(pattern
+ " is substring of main string, match found at: "
+ ++i);
}
}
sc.close();
}
}
Output:
$ javac StringSearchUsingStrLib.java $ java StringSearchUsingStrLib Enter the main string: Java Program to Perform String Matching Using String Library Enter the pattern string: String String is substring of main string, match found at: 25 String is substring of main string, match found at: 47
Related posts:
Java Program to Compute Cross Product of Two Vectors
Java Stream Filter with Lambda Expression
Registration with Spring Security – Password Encoding
Java Program to Create a Random Linear Extension for a DAG
Java Program to Implement LinkedBlockingDeque API
Testing in Spring Boot
Java Program to Find the Vertex Connectivity of a Graph
Refactoring Design Pattern với tính năng mới trong Java 8
A Guide to Concurrent Queues in Java
Send an email using the SMTP protocol
Setting Up Swagger 2 with a Spring REST API
Java Byte Array to InputStream
Java Program to Implement Sorted Array
Sorting in Java
XML Serialization and Deserialization with Jackson
HashSet trong Java hoạt động như thế nào?
Merging Streams in Java
Introduction to Java 8 Streams
Spring Boot - Google Cloud Platform
Spring MVC Content Negotiation
Simultaneous Spring WebClient Calls
Custom Thread Pools In Java 8 Parallel Streams
Properties with Spring and Spring Boot
Receive email using IMAP
Java Program to Find Transpose of a Graph Matrix
Spring Webflux with Kotlin
Send email with authentication
Java 8 Stream API Analogies in Kotlin
Java Program to Show the Duality Transformation of Line and Point
Overview of Spring Boot Dev Tools
Java Program to Check the Connectivity of Graph Using DFS
Adding Shutdown Hooks for JVM Applications