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:
Guide to @ConfigurationProperties in Spring Boot
Java Program to Implement LinkedTransferQueue API
Spring Boot with Multiple SQL Import Files
A Guide to TreeMap in Java
Java Program to Perform Polygon Containment Test
Spring Boot - Google Cloud Platform
Spring Boot - Hystrix
How to Set TLS Version in Apache HttpClient
Display Auto-Configuration Report in Spring Boot
Biểu thức Lambda trong Java 8 – Lambda Expressions
Java Program to Implement Miller Rabin Primality Test Algorithm
Model, ModelMap, and ModelAndView in Spring MVC
Java Program to Implement Graham Scan Algorithm to Find the Convex Hull
A Guide to @RepeatedTest in Junit 5
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Spring Cloud Series – The Gateway Pattern
Comparing Arrays in Java
Guide to System.gc()
Java Program to Find MST (Minimum Spanning Tree) using Prim’s Algorithm
Java Program to Describe the Representation of Graph using Adjacency Matrix
Java – Generate Random String
Tìm hiểu về Web Service
Circular Dependencies in Spring
Java Convenience Factory Methods for Collections
Java Program to Implement String Matching Using Vectors
Batch Processing with Spring Cloud Data Flow
New Features in Java 8
Weak References in Java
LinkedHashSet trong java
A Guide To UDP In Java
Jackson JSON Views
Converting String to Stream of chars