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:
Spring Cloud Connectors and Heroku
HttpClient 4 Cookbook
Java Program to Check Whether it is Weakly Connected or Strongly Connected for a Directed Graph
Exploring the Spring 5 WebFlux URL Matching
Java Program to Implement Weight Balanced Tree
Java Program to Optimize Wire Length in Electrical Circuit
Error Handling for REST with Spring
A Quick Guide to Spring Cloud Consul
Java Program to implement Associate Array
Java Program to Implement LinkedTransferQueue API
How to Convert List to Map in Java
Guide to WeakHashMap in Java
Netflix Archaius with Various Database Configurations
Converting Between Byte Arrays and Hexadecimal Strings in Java
Hướng dẫn Java Design Pattern – Builder
Spring Boot Tutorial – Bootstrap a Simple Application
Find the Registered Spring Security Filters
Java Program to Perform the Sorting Using Counting Sort
@Order in Spring
Java Program to Find the Longest Path in a DAG
Java Program to Implement Depth-limited Search
Java Timer
A Guide to EnumMap
Java Program to Find Transitive Closure of a Graph
A Quick Guide to Spring MVC Matrix Variables
Biến trong java
Spring Security Remember Me
Java Program to Check Multiplicability of Two Matrices
Java Program to find the number of occurrences of a given number using Binary Search approach
Java Program to Implement Flood Fill Algorithm
An Intro to Spring Cloud Task
Tiêu chuẩn coding trong Java (Coding Standards)